@@ -5,6 +5,7 @@ import { expect } from "chai";
55
66import DatabaseImporter from "../../database/import" ;
77import { FirebaseError } from "../../error" ;
8+ import { FetchError } from "node-fetch" ;
89
910const dbUrl = new URL ( "https://test-db.firebaseio.com/foo" ) ;
1011const chunkSize = 1024 * 1024 * 10 ;
@@ -112,4 +113,33 @@ describe("DatabaseImporter", () => {
112113 / I m p o r t i n g i s o n l y a l l o w e d f o r a n e m p t y l o c a t i o n ./
113114 ) ;
114115 } ) ;
116+
117+ it ( "retries non-fatal connection timeout error" , async ( ) => {
118+ const timeoutErr = new FetchError ( "connect ETIMEDOUT" , "system" ) ;
119+ timeoutErr . code = "ETIMEDOUT" ;
120+
121+ nock ( "https://test-db.firebaseio.com" ) . get ( "/foo.json?shallow=true" ) . reply ( 200 ) ;
122+ nock ( "https://test-db.firebaseio.com" )
123+ . put ( "/foo/a.json" , "100" )
124+ . once ( )
125+ . replyWithError ( timeoutErr ) ;
126+ nock ( "https://test-db.firebaseio.com" ) . put ( "/foo/a.json" , "100" ) . once ( ) . reply ( 200 ) ;
127+ nock ( "https://test-db.firebaseio.com" )
128+ . put ( "/foo/b.json" , JSON . stringify ( [ true , "bar" , { f : { g : 0 , h : 1 } , i : "baz" } ] ) )
129+ . reply ( 200 ) ;
130+
131+ const importer = new DatabaseImporter (
132+ dbUrl ,
133+ DATA_STREAM ,
134+ /* importPath= */ "/" ,
135+ chunkSize ,
136+ concurrencyLimit
137+ ) ;
138+ importer . nonFatalRetryTimeout = 0 ;
139+
140+ const responses = await importer . execute ( ) ;
141+
142+ expect ( responses ) . to . have . length ( 2 ) ;
143+ expect ( nock . isDone ( ) ) . to . be . true ;
144+ } ) ;
115145} ) ;
0 commit comments