@@ -37,98 +37,6 @@ describe('Socket Errors', () => {
37
37
} ) ;
38
38
} ) ;
39
39
40
- describe ( 'when destroyed after write' , ( ) => {
41
- let client : MongoClient ;
42
- let collection ;
43
-
44
- beforeEach ( async function ( ) {
45
- client = this . configuration . newClient ( { } , { appName : 'failInserts' } ) ;
46
- await client . connect ( ) ;
47
- const db = client . db ( 'closeConn' ) ;
48
- collection = db . collection ( 'closeConn' ) ;
49
-
50
- const checkOut = sinon . stub ( ConnectionPool . prototype , 'checkOut' ) . callsFake ( fakeCheckout ) ;
51
- async function fakeCheckout ( ...args ) {
52
- const connection = await checkOut . wrappedMethod . call ( this , ...args ) ;
53
-
54
- const write = sinon . stub ( connection . socket , 'write' ) . callsFake ( function ( ...args ) {
55
- queueMicrotask ( ( ) => {
56
- this . destroy ( new Error ( 'read ECONNRESET' ) ) ;
57
- } ) ;
58
- return write . wrappedMethod . call ( this , ...args ) ;
59
- } ) ;
60
-
61
- return connection ;
62
- }
63
- } ) ;
64
-
65
- afterEach ( async function ( ) {
66
- sinon . restore ( ) ;
67
- await client . close ( ) ;
68
- } ) ;
69
-
70
- it ( 'throws a MongoNetworkError' , async ( ) => {
71
- const error = await collection . insertOne ( { name : 'test' } ) . catch ( error => error ) ;
72
- expect ( error ) . to . be . instanceOf ( MongoNetworkError ) ;
73
- } ) ;
74
- } ) ;
75
-
76
- describe ( 'when destroyed after read' , ( ) => {
77
- let client : MongoClient ;
78
- let collection ;
79
-
80
- const metadata : MongoDBMetadataUI = { requires : { mongodb : '>=4.4' } } ;
81
-
82
- beforeEach ( async function ( ) {
83
- if ( ! this . configuration . filters . NodeVersionFilter . filter ( { metadata } ) ) {
84
- return ;
85
- }
86
-
87
- await configureFailPoint ( this . configuration , {
88
- configureFailPoint : 'failCommand' ,
89
- mode : 'alwaysOn' ,
90
- data : {
91
- appName : 'failInserts' ,
92
- failCommands : [ 'insert' ] ,
93
- blockConnection : true ,
94
- blockTimeMS : 1000 // just so the server doesn't reply super fast.
95
- }
96
- } ) ;
97
-
98
- client = this . configuration . newClient ( { } , { appName : 'failInserts' } ) ;
99
- await client . connect ( ) ;
100
- const db = client . db ( 'closeConn' ) ;
101
- collection = db . collection ( 'closeConn' ) ;
102
-
103
- const checkOut = sinon . stub ( ConnectionPool . prototype , 'checkOut' ) . callsFake ( fakeCheckout ) ;
104
- async function fakeCheckout ( ...args ) {
105
- const connection = await checkOut . wrappedMethod . call ( this , ...args ) ;
106
-
107
- const on = sinon . stub ( connection . messageStream , 'on' ) . callsFake ( function ( ...args ) {
108
- if ( args [ 0 ] === 'data' ) {
109
- queueMicrotask ( ( ) => {
110
- connection . socket . destroy ( new Error ( 'read ECONNRESET' ) ) ;
111
- } ) ;
112
- }
113
- return on . wrappedMethod . call ( this , ...args ) ;
114
- } ) ;
115
-
116
- return connection ;
117
- }
118
- } ) ;
119
-
120
- afterEach ( async function ( ) {
121
- sinon . restore ( ) ;
122
- await clearFailPoint ( this . configuration ) ;
123
- await client . close ( ) ;
124
- } ) ;
125
-
126
- it ( 'throws a MongoNetworkError' , metadata , async ( ) => {
127
- const error = await collection . insertOne ( { name : 'test' } ) . catch ( error => error ) ;
128
- expect ( error ) . to . be . instanceOf ( MongoNetworkError ) ;
129
- } ) ;
130
- } ) ;
131
-
132
40
describe ( 'when destroyed by failpoint' , ( ) => {
133
41
let client : MongoClient ;
134
42
let collection ;
0 commit comments