|
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | 5 |
|
6 | 6 | import * as assert from 'assert'; |
7 | | -import { IUserDataSyncService, UserDataSyncError, UserDataSyncErrorCode } from 'vs/platform/userDataSync/common/userDataSync'; |
| 7 | +import { IUserDataSyncService, UserDataSyncError, UserDataSyncErrorCode, SyncStatus, SyncSource } from 'vs/platform/userDataSync/common/userDataSync'; |
8 | 8 | import { UserDataSyncClient, UserDataSyncTestServer } from 'vs/platform/userDataSync/test/common/userDataSyncClient'; |
9 | 9 | import { DisposableStore } from 'vs/base/common/lifecycle'; |
10 | 10 | import { IFileService } from 'vs/platform/files/common/files'; |
@@ -371,4 +371,116 @@ suite('UserDataSyncService', () => { |
371 | 371 | throw assert.fail('Should fail with turned off error'); |
372 | 372 | }); |
373 | 373 |
|
| 374 | + test('test sync status', async () => { |
| 375 | + const target = new UserDataSyncTestServer(); |
| 376 | + |
| 377 | + // Setup the client |
| 378 | + const client = disposableStore.add(new UserDataSyncClient(target)); |
| 379 | + await client.setUp(); |
| 380 | + const testObject = client.instantiationService.get(IUserDataSyncService); |
| 381 | + |
| 382 | + // sync from the client |
| 383 | + const actualStatuses: SyncStatus[] = []; |
| 384 | + const disposable = testObject.onDidChangeStatus(status => actualStatuses.push(status)); |
| 385 | + await testObject.sync(); |
| 386 | + |
| 387 | + disposable.dispose(); |
| 388 | + assert.deepEqual(actualStatuses, [SyncStatus.Syncing, SyncStatus.Idle, SyncStatus.Syncing, SyncStatus.Idle, SyncStatus.Syncing, SyncStatus.Idle, SyncStatus.Syncing, SyncStatus.Idle]); |
| 389 | + }); |
| 390 | + |
| 391 | + test('test sync conflicts status', async () => { |
| 392 | + const target = new UserDataSyncTestServer(); |
| 393 | + |
| 394 | + // Setup and sync from the first client |
| 395 | + const client = disposableStore.add(new UserDataSyncClient(target)); |
| 396 | + await client.setUp(); |
| 397 | + let fileService = client.instantiationService.get(IFileService); |
| 398 | + let environmentService = client.instantiationService.get(IEnvironmentService); |
| 399 | + await fileService.writeFile(environmentService.settingsResource, VSBuffer.fromString(JSON.stringify({ 'editor.fontSize': 14 }))); |
| 400 | + await client.instantiationService.get(IUserDataSyncService).sync(); |
| 401 | + |
| 402 | + // Setup the test client |
| 403 | + const testClient = disposableStore.add(new UserDataSyncClient(target)); |
| 404 | + await testClient.setUp(); |
| 405 | + fileService = testClient.instantiationService.get(IFileService); |
| 406 | + environmentService = testClient.instantiationService.get(IEnvironmentService); |
| 407 | + await fileService.writeFile(environmentService.settingsResource, VSBuffer.fromString(JSON.stringify({ 'editor.fontSize': 16 }))); |
| 408 | + const testObject = testClient.instantiationService.get(IUserDataSyncService); |
| 409 | + |
| 410 | + // sync from the client |
| 411 | + await testObject.sync(); |
| 412 | + |
| 413 | + assert.deepEqual(testObject.status, SyncStatus.HasConflicts); |
| 414 | + assert.deepEqual(testObject.conflictsSources, [SyncSource.Settings]); |
| 415 | + }); |
| 416 | + |
| 417 | + test('test sync will sync other non conflicted areas', async () => { |
| 418 | + const target = new UserDataSyncTestServer(); |
| 419 | + |
| 420 | + // Setup and sync from the first client |
| 421 | + const client = disposableStore.add(new UserDataSyncClient(target)); |
| 422 | + await client.setUp(); |
| 423 | + let fileService = client.instantiationService.get(IFileService); |
| 424 | + let environmentService = client.instantiationService.get(IEnvironmentService); |
| 425 | + await fileService.writeFile(environmentService.settingsResource, VSBuffer.fromString(JSON.stringify({ 'editor.fontSize': 14 }))); |
| 426 | + await client.instantiationService.get(IUserDataSyncService).sync(); |
| 427 | + |
| 428 | + // Setup the test client and get conflicts in settings |
| 429 | + const testClient = disposableStore.add(new UserDataSyncClient(target)); |
| 430 | + await testClient.setUp(); |
| 431 | + let testFileService = testClient.instantiationService.get(IFileService); |
| 432 | + let testEnvironmentService = testClient.instantiationService.get(IEnvironmentService); |
| 433 | + await testFileService.writeFile(testEnvironmentService.settingsResource, VSBuffer.fromString(JSON.stringify({ 'editor.fontSize': 16 }))); |
| 434 | + const testObject = testClient.instantiationService.get(IUserDataSyncService); |
| 435 | + await testObject.sync(); |
| 436 | + |
| 437 | + // sync from the first client with changes in keybindings |
| 438 | + await fileService.writeFile(environmentService.keybindingsResource, VSBuffer.fromString(JSON.stringify([{ 'command': 'abcd', 'key': 'cmd+c' }]))); |
| 439 | + await client.instantiationService.get(IUserDataSyncService).sync(); |
| 440 | + |
| 441 | + // sync from the test client |
| 442 | + target.reset(); |
| 443 | + const actualStatuses: SyncStatus[] = []; |
| 444 | + const disposable = testObject.onDidChangeStatus(status => actualStatuses.push(status)); |
| 445 | + await testObject.sync(); |
| 446 | + |
| 447 | + disposable.dispose(); |
| 448 | + assert.deepEqual(actualStatuses, []); |
| 449 | + assert.deepEqual(testObject.status, SyncStatus.HasConflicts); |
| 450 | + |
| 451 | + assert.deepEqual(target.requests, [ |
| 452 | + // Manifest |
| 453 | + { type: 'GET', url: `${target.url}/v1/manifest`, headers: {} }, |
| 454 | + // Keybindings |
| 455 | + { type: 'GET', url: `${target.url}/v1/resource/keybindings/latest`, headers: { 'If-None-Match': '1' } }, |
| 456 | + ]); |
| 457 | + }); |
| 458 | + |
| 459 | + test('test stop sync reset status', async () => { |
| 460 | + const target = new UserDataSyncTestServer(); |
| 461 | + |
| 462 | + // Setup and sync from the first client |
| 463 | + const client = disposableStore.add(new UserDataSyncClient(target)); |
| 464 | + await client.setUp(); |
| 465 | + let fileService = client.instantiationService.get(IFileService); |
| 466 | + let environmentService = client.instantiationService.get(IEnvironmentService); |
| 467 | + await fileService.writeFile(environmentService.settingsResource, VSBuffer.fromString(JSON.stringify({ 'editor.fontSize': 14 }))); |
| 468 | + await client.instantiationService.get(IUserDataSyncService).sync(); |
| 469 | + |
| 470 | + // Setup the test client |
| 471 | + const testClient = disposableStore.add(new UserDataSyncClient(target)); |
| 472 | + await testClient.setUp(); |
| 473 | + fileService = testClient.instantiationService.get(IFileService); |
| 474 | + environmentService = testClient.instantiationService.get(IEnvironmentService); |
| 475 | + await fileService.writeFile(environmentService.settingsResource, VSBuffer.fromString(JSON.stringify({ 'editor.fontSize': 16 }))); |
| 476 | + const testObject = testClient.instantiationService.get(IUserDataSyncService); |
| 477 | + await testObject.sync(); |
| 478 | + |
| 479 | + // sync from the client |
| 480 | + await testObject.stop(); |
| 481 | + |
| 482 | + assert.deepEqual(testObject.status, SyncStatus.Idle); |
| 483 | + assert.deepEqual(testObject.conflictsSources, []); |
| 484 | + }); |
| 485 | + |
374 | 486 | }); |
0 commit comments