@@ -23,7 +23,10 @@ describe("query history scrubber", () => {
2323 // We don't want our times to align exactly with the hour,
2424 // so we can better mimic real life
2525 const LESS_THAN_ONE_DAY = ONE_DAY_IN_MS - 1000 ;
26- const tmpDir = dirSync ( {
26+ const tmpLocalQueriesDir = dirSync ( {
27+ unsafeCleanup : true ,
28+ } ) ;
29+ const tmpVariantAnalysesDir = dirSync ( {
2730 unsafeCleanup : true ,
2831 } ) ;
2932
@@ -62,7 +65,7 @@ describe("query history scrubber", () => {
6265 } ) ;
6366
6467 it ( "should not throw an error when the query directory does not exist" , async ( ) => {
65- registerScrubber ( "idontexist " ) ;
68+ registerScrubber ( "idontexist1" , "idontexist2 ") ;
6669
6770 jest . advanceTimersByTime ( ONE_HOUR_IN_MS ) ;
6871 await wait ( ) ;
@@ -89,21 +92,35 @@ describe("query history scrubber", () => {
8992 ) ;
9093 } ) ;
9194
92- it ( "should scrub directories" , async ( ) => {
95+ it ( "should scrub local query directories" , async ( ) => {
9396 // create two query directories that are right around the cut off time
94- const queryDir = createMockQueryDir (
97+ const localQueriesDir = createMockQueryDir (
98+ tmpLocalQueriesDir . name ,
9599 ONE_HOUR_IN_MS ,
96100 TWO_HOURS_IN_MS ,
97101 THREE_HOURS_IN_MS ,
98102 ) ;
99- registerScrubber ( queryDir ) ;
103+ const variantAnalysesDir = createMockQueryDir (
104+ tmpVariantAnalysesDir . name ,
105+ ONE_HOUR_IN_MS ,
106+ TWO_HOURS_IN_MS ,
107+ THREE_HOURS_IN_MS ,
108+ ) ;
109+ registerScrubber ( localQueriesDir , variantAnalysesDir ) ;
100110
101111 jest . advanceTimersByTime ( TWO_HOURS_IN_MS ) ;
102112 await wait ( ) ;
103113
104114 // should have deleted only the invalid locations
105115 expectDirectories (
106- queryDir ,
116+ localQueriesDir ,
117+ toQueryDirName ( ONE_HOUR_IN_MS ) ,
118+ toQueryDirName ( TWO_HOURS_IN_MS ) ,
119+ toQueryDirName ( THREE_HOURS_IN_MS ) ,
120+ ) ;
121+
122+ expectDirectories (
123+ variantAnalysesDir ,
107124 toQueryDirName ( ONE_HOUR_IN_MS ) ,
108125 toQueryDirName ( TWO_HOURS_IN_MS ) ,
109126 toQueryDirName ( THREE_HOURS_IN_MS ) ,
@@ -114,7 +131,14 @@ describe("query history scrubber", () => {
114131
115132 // nothing should have happened...yet
116133 expectDirectories (
117- queryDir ,
134+ localQueriesDir ,
135+ toQueryDirName ( ONE_HOUR_IN_MS ) ,
136+ toQueryDirName ( TWO_HOURS_IN_MS ) ,
137+ toQueryDirName ( THREE_HOURS_IN_MS ) ,
138+ ) ;
139+
140+ expectDirectories (
141+ variantAnalysesDir ,
118142 toQueryDirName ( ONE_HOUR_IN_MS ) ,
119143 toQueryDirName ( TWO_HOURS_IN_MS ) ,
120144 toQueryDirName ( THREE_HOURS_IN_MS ) ,
@@ -126,23 +150,24 @@ describe("query history scrubber", () => {
126150 // should have deleted the two older directories
127151 // even though they have different time stamps,
128152 // they both expire during the same scrubbing period
129- expectDirectories ( queryDir , toQueryDirName ( THREE_HOURS_IN_MS ) ) ;
153+ expectDirectories ( localQueriesDir , toQueryDirName ( THREE_HOURS_IN_MS ) ) ;
154+ expectDirectories ( variantAnalysesDir , toQueryDirName ( THREE_HOURS_IN_MS ) ) ;
130155
131156 // Wait until the next scrub time and the final directory is deleted
132157 jest . advanceTimersByTime ( TWO_HOURS_IN_MS ) ;
133158 await wait ( ) ;
134159
135160 // should have deleted everything
136- expectDirectories ( queryDir ) ;
161+ expectDirectories ( localQueriesDir ) ;
162+ expectDirectories ( variantAnalysesDir ) ;
137163 } ) ;
138164
139165 function expectDirectories ( queryDir : string , ...dirNames : string [ ] ) {
140166 const files = readdirSync ( queryDir ) ;
141167 expect ( files . sort ( ) ) . toEqual ( dirNames . sort ( ) ) ;
142168 }
143169
144- function createMockQueryDir ( ...timestamps : number [ ] ) {
145- const dir = tmpDir . name ;
170+ function createMockQueryDir ( dir : string , ...timestamps : number [ ] ) {
146171 const queryDir = join ( dir , "query" ) ;
147172 // create qyuery directory and fill it with some query directories
148173 mkdirSync ( queryDir ) ;
@@ -175,12 +200,15 @@ describe("query history scrubber", () => {
175200 return `query-${ timestamp } ` ;
176201 }
177202
178- function registerScrubber ( dir : string ) {
203+ function registerScrubber (
204+ localQueriesDirPath : string ,
205+ variantAnalysesDirPath : string ,
206+ ) {
179207 deregister = registerQueryHistoryScrubber (
180208 ONE_HOUR_IN_MS ,
181209 TWO_HOURS_IN_MS ,
182210 LESS_THAN_ONE_DAY ,
183- { localQueriesDirPath : dir , variantAnalysesDirPath : dir } ,
211+ { localQueriesDirPath, variantAnalysesDirPath } ,
184212 {
185213 removeDeletedQueries : ( ) => {
186214 return Promise . resolve ( ) ;
0 commit comments