@@ -13,6 +13,7 @@ import * as platform from 'vs/base/common/platform';
13
13
import { isEqual } from 'vs/base/common/resources' ;
14
14
import { URI } from 'vs/base/common/uri' ;
15
15
import * as pfs from 'vs/base/node/pfs' ;
16
+ import { runWithFakedTimers } from 'vs/base/test/common/timeTravelScheduler' ;
16
17
import { flakySuite , getRandomTestPath } from 'vs/base/test/node/testUtils' ;
17
18
import { IWorkspaceBackupInfo } from 'vs/platform/backup/electron-main/backup' ;
18
19
import { BackupMainService } from 'vs/platform/backup/electron-main/backupMainService' ;
@@ -136,93 +137,97 @@ flakySuite('BackupMainService', () => {
136
137
} ) ;
137
138
138
139
test ( 'service validates backup workspaces on startup and cleans up (folder workspaces)' , async function ( ) {
140
+ runWithFakedTimers ( { } , async ( ) => {
139
141
140
- // 1) backup workspace path does not exist
141
- service . registerFolderBackupSync ( fooFile ) ;
142
- service . registerFolderBackupSync ( barFile ) ;
143
- await service . initialize ( ) ;
144
- assertEqualUris ( service . getFolderBackupPaths ( ) , [ ] ) ;
145
-
146
- // 2) backup workspace path exists with empty contents within
147
- fs . mkdirSync ( service . toBackupPath ( fooFile ) ) ;
148
- fs . mkdirSync ( service . toBackupPath ( barFile ) ) ;
149
- service . registerFolderBackupSync ( fooFile ) ;
150
- service . registerFolderBackupSync ( barFile ) ;
151
- await service . initialize ( ) ;
152
- assertEqualUris ( service . getFolderBackupPaths ( ) , [ ] ) ;
153
- assert . ok ( ! fs . existsSync ( service . toBackupPath ( fooFile ) ) ) ;
154
- assert . ok ( ! fs . existsSync ( service . toBackupPath ( barFile ) ) ) ;
155
-
156
- // 3) backup workspace path exists with empty folders within
157
- fs . mkdirSync ( service . toBackupPath ( fooFile ) ) ;
158
- fs . mkdirSync ( service . toBackupPath ( barFile ) ) ;
159
- fs . mkdirSync ( path . join ( service . toBackupPath ( fooFile ) , Schemas . file ) ) ;
160
- fs . mkdirSync ( path . join ( service . toBackupPath ( barFile ) , Schemas . untitled ) ) ;
161
- service . registerFolderBackupSync ( fooFile ) ;
162
- service . registerFolderBackupSync ( barFile ) ;
163
- await service . initialize ( ) ;
164
- assertEqualUris ( service . getFolderBackupPaths ( ) , [ ] ) ;
165
- assert . ok ( ! fs . existsSync ( service . toBackupPath ( fooFile ) ) ) ;
166
- assert . ok ( ! fs . existsSync ( service . toBackupPath ( barFile ) ) ) ;
167
-
168
- // 4) backup workspace path points to a workspace that no longer exists
169
- // so it should convert the backup worspace to an empty workspace backup
170
- const fileBackups = path . join ( service . toBackupPath ( fooFile ) , Schemas . file ) ;
171
- fs . mkdirSync ( service . toBackupPath ( fooFile ) ) ;
172
- fs . mkdirSync ( service . toBackupPath ( barFile ) ) ;
173
- fs . mkdirSync ( fileBackups ) ;
174
- service . registerFolderBackupSync ( fooFile ) ;
175
- assert . strictEqual ( service . getFolderBackupPaths ( ) . length , 1 ) ;
176
- assert . strictEqual ( service . getEmptyWindowBackupPaths ( ) . length , 0 ) ;
177
- fs . writeFileSync ( path . join ( fileBackups , 'backup.txt' ) , '' ) ;
178
- await service . initialize ( ) ;
179
- assert . strictEqual ( service . getFolderBackupPaths ( ) . length , 0 ) ;
180
- assert . strictEqual ( service . getEmptyWindowBackupPaths ( ) . length , 1 ) ;
142
+ // 1) backup workspace path does not exist
143
+ service . registerFolderBackupSync ( fooFile ) ;
144
+ service . registerFolderBackupSync ( barFile ) ;
145
+ await service . initialize ( ) ;
146
+ assertEqualUris ( service . getFolderBackupPaths ( ) , [ ] ) ;
147
+
148
+ // 2) backup workspace path exists with empty contents within
149
+ fs . mkdirSync ( service . toBackupPath ( fooFile ) ) ;
150
+ fs . mkdirSync ( service . toBackupPath ( barFile ) ) ;
151
+ service . registerFolderBackupSync ( fooFile ) ;
152
+ service . registerFolderBackupSync ( barFile ) ;
153
+ await service . initialize ( ) ;
154
+ assertEqualUris ( service . getFolderBackupPaths ( ) , [ ] ) ;
155
+ assert . ok ( ! fs . existsSync ( service . toBackupPath ( fooFile ) ) ) ;
156
+ assert . ok ( ! fs . existsSync ( service . toBackupPath ( barFile ) ) ) ;
157
+
158
+ // 3) backup workspace path exists with empty folders within
159
+ fs . mkdirSync ( service . toBackupPath ( fooFile ) ) ;
160
+ fs . mkdirSync ( service . toBackupPath ( barFile ) ) ;
161
+ fs . mkdirSync ( path . join ( service . toBackupPath ( fooFile ) , Schemas . file ) ) ;
162
+ fs . mkdirSync ( path . join ( service . toBackupPath ( barFile ) , Schemas . untitled ) ) ;
163
+ service . registerFolderBackupSync ( fooFile ) ;
164
+ service . registerFolderBackupSync ( barFile ) ;
165
+ await service . initialize ( ) ;
166
+ assertEqualUris ( service . getFolderBackupPaths ( ) , [ ] ) ;
167
+ assert . ok ( ! fs . existsSync ( service . toBackupPath ( fooFile ) ) ) ;
168
+ assert . ok ( ! fs . existsSync ( service . toBackupPath ( barFile ) ) ) ;
169
+
170
+ // 4) backup workspace path points to a workspace that no longer exists
171
+ // so it should convert the backup worspace to an empty workspace backup
172
+ const fileBackups = path . join ( service . toBackupPath ( fooFile ) , Schemas . file ) ;
173
+ fs . mkdirSync ( service . toBackupPath ( fooFile ) ) ;
174
+ fs . mkdirSync ( service . toBackupPath ( barFile ) ) ;
175
+ fs . mkdirSync ( fileBackups ) ;
176
+ service . registerFolderBackupSync ( fooFile ) ;
177
+ assert . strictEqual ( service . getFolderBackupPaths ( ) . length , 1 ) ;
178
+ assert . strictEqual ( service . getEmptyWindowBackupPaths ( ) . length , 0 ) ;
179
+ fs . writeFileSync ( path . join ( fileBackups , 'backup.txt' ) , '' ) ;
180
+ await service . initialize ( ) ;
181
+ assert . strictEqual ( service . getFolderBackupPaths ( ) . length , 0 ) ;
182
+ assert . strictEqual ( service . getEmptyWindowBackupPaths ( ) . length , 1 ) ;
183
+ } ) ;
181
184
} ) ;
182
185
183
186
test ( 'service validates backup workspaces on startup and cleans up (root workspaces)' , async function ( ) {
187
+ runWithFakedTimers ( { } , async ( ) => {
188
+
189
+ // 1) backup workspace path does not exist
190
+ service . registerWorkspaceBackupSync ( toWorkspaceBackupInfo ( fooFile . fsPath ) ) ;
191
+ service . registerWorkspaceBackupSync ( toWorkspaceBackupInfo ( barFile . fsPath ) ) ;
192
+ await service . initialize ( ) ;
193
+ assert . deepStrictEqual ( service . getWorkspaceBackups ( ) , [ ] ) ;
184
194
185
- // 1) backup workspace path does not exist
186
- service . registerWorkspaceBackupSync ( toWorkspaceBackupInfo ( fooFile . fsPath ) ) ;
187
- service . registerWorkspaceBackupSync ( toWorkspaceBackupInfo ( barFile . fsPath ) ) ;
188
- await service . initialize ( ) ;
189
- assert . deepStrictEqual ( service . getWorkspaceBackups ( ) , [ ] ) ;
190
-
191
- // 2) backup workspace path exists with empty contents within
192
- fs . mkdirSync ( service . toBackupPath ( fooFile ) ) ;
193
- fs . mkdirSync ( service . toBackupPath ( barFile ) ) ;
194
- service . registerWorkspaceBackupSync ( toWorkspaceBackupInfo ( fooFile . fsPath ) ) ;
195
- service . registerWorkspaceBackupSync ( toWorkspaceBackupInfo ( barFile . fsPath ) ) ;
196
- await service . initialize ( ) ;
197
- assert . deepStrictEqual ( service . getWorkspaceBackups ( ) , [ ] ) ;
198
- assert . ok ( ! fs . existsSync ( service . toBackupPath ( fooFile ) ) ) ;
199
- assert . ok ( ! fs . existsSync ( service . toBackupPath ( barFile ) ) ) ;
200
-
201
- // 3) backup workspace path exists with empty folders within
202
- fs . mkdirSync ( service . toBackupPath ( fooFile ) ) ;
203
- fs . mkdirSync ( service . toBackupPath ( barFile ) ) ;
204
- fs . mkdirSync ( path . join ( service . toBackupPath ( fooFile ) , Schemas . file ) ) ;
205
- fs . mkdirSync ( path . join ( service . toBackupPath ( barFile ) , Schemas . untitled ) ) ;
206
- service . registerWorkspaceBackupSync ( toWorkspaceBackupInfo ( fooFile . fsPath ) ) ;
207
- service . registerWorkspaceBackupSync ( toWorkspaceBackupInfo ( barFile . fsPath ) ) ;
208
- await service . initialize ( ) ;
209
- assert . deepStrictEqual ( service . getWorkspaceBackups ( ) , [ ] ) ;
210
- assert . ok ( ! fs . existsSync ( service . toBackupPath ( fooFile ) ) ) ;
211
- assert . ok ( ! fs . existsSync ( service . toBackupPath ( barFile ) ) ) ;
212
-
213
- // 4) backup workspace path points to a workspace that no longer exists
214
- // so it should convert the backup worspace to an empty workspace backup
215
- const fileBackups = path . join ( service . toBackupPath ( fooFile ) , Schemas . file ) ;
216
- fs . mkdirSync ( service . toBackupPath ( fooFile ) ) ;
217
- fs . mkdirSync ( service . toBackupPath ( barFile ) ) ;
218
- fs . mkdirSync ( fileBackups ) ;
219
- service . registerWorkspaceBackupSync ( toWorkspaceBackupInfo ( fooFile . fsPath ) ) ;
220
- assert . strictEqual ( service . getWorkspaceBackups ( ) . length , 1 ) ;
221
- assert . strictEqual ( service . getEmptyWindowBackupPaths ( ) . length , 0 ) ;
222
- fs . writeFileSync ( path . join ( fileBackups , 'backup.txt' ) , '' ) ;
223
- await service . initialize ( ) ;
224
- assert . strictEqual ( service . getWorkspaceBackups ( ) . length , 0 ) ;
225
- assert . strictEqual ( service . getEmptyWindowBackupPaths ( ) . length , 1 ) ;
195
+ // 2) backup workspace path exists with empty contents within
196
+ fs . mkdirSync ( service . toBackupPath ( fooFile ) ) ;
197
+ fs . mkdirSync ( service . toBackupPath ( barFile ) ) ;
198
+ service . registerWorkspaceBackupSync ( toWorkspaceBackupInfo ( fooFile . fsPath ) ) ;
199
+ service . registerWorkspaceBackupSync ( toWorkspaceBackupInfo ( barFile . fsPath ) ) ;
200
+ await service . initialize ( ) ;
201
+ assert . deepStrictEqual ( service . getWorkspaceBackups ( ) , [ ] ) ;
202
+ assert . ok ( ! fs . existsSync ( service . toBackupPath ( fooFile ) ) ) ;
203
+ assert . ok ( ! fs . existsSync ( service . toBackupPath ( barFile ) ) ) ;
204
+
205
+ // 3) backup workspace path exists with empty folders within
206
+ fs . mkdirSync ( service . toBackupPath ( fooFile ) ) ;
207
+ fs . mkdirSync ( service . toBackupPath ( barFile ) ) ;
208
+ fs . mkdirSync ( path . join ( service . toBackupPath ( fooFile ) , Schemas . file ) ) ;
209
+ fs . mkdirSync ( path . join ( service . toBackupPath ( barFile ) , Schemas . untitled ) ) ;
210
+ service . registerWorkspaceBackupSync ( toWorkspaceBackupInfo ( fooFile . fsPath ) ) ;
211
+ service . registerWorkspaceBackupSync ( toWorkspaceBackupInfo ( barFile . fsPath ) ) ;
212
+ await service . initialize ( ) ;
213
+ assert . deepStrictEqual ( service . getWorkspaceBackups ( ) , [ ] ) ;
214
+ assert . ok ( ! fs . existsSync ( service . toBackupPath ( fooFile ) ) ) ;
215
+ assert . ok ( ! fs . existsSync ( service . toBackupPath ( barFile ) ) ) ;
216
+
217
+ // 4) backup workspace path points to a workspace that no longer exists
218
+ // so it should convert the backup worspace to an empty workspace backup
219
+ const fileBackups = path . join ( service . toBackupPath ( fooFile ) , Schemas . file ) ;
220
+ fs . mkdirSync ( service . toBackupPath ( fooFile ) ) ;
221
+ fs . mkdirSync ( service . toBackupPath ( barFile ) ) ;
222
+ fs . mkdirSync ( fileBackups ) ;
223
+ service . registerWorkspaceBackupSync ( toWorkspaceBackupInfo ( fooFile . fsPath ) ) ;
224
+ assert . strictEqual ( service . getWorkspaceBackups ( ) . length , 1 ) ;
225
+ assert . strictEqual ( service . getEmptyWindowBackupPaths ( ) . length , 0 ) ;
226
+ fs . writeFileSync ( path . join ( fileBackups , 'backup.txt' ) , '' ) ;
227
+ await service . initialize ( ) ;
228
+ assert . strictEqual ( service . getWorkspaceBackups ( ) . length , 0 ) ;
229
+ assert . strictEqual ( service . getEmptyWindowBackupPaths ( ) . length , 1 ) ;
230
+ } ) ;
226
231
} ) ;
227
232
228
233
test ( 'service supports to migrate backup data from another location' , ( ) => {
0 commit comments