Skip to content

Commit

Permalink
Properly return a non 0 exit code in case a test times out and fix te…
Browse files Browse the repository at this point in the history
…sts which used to time out (microsoft#152329)
  • Loading branch information
alexdima authored Jun 16, 2022
1 parent 192f8bf commit 3530e85
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ suite('UserDataAutoSyncService', () => {
teardown(() => disposableStore.clear());

test('test auto sync with sync resource change triggers sync', async () => {
await runWithFakedTimers({ useSetImmediate: true }, async () => {
await runWithFakedTimers({}, async () => {
// Setup the client
const target = new UserDataSyncTestServer();
const client = disposableStore.add(new UserDataSyncClient(target));
Expand All @@ -57,7 +57,7 @@ suite('UserDataAutoSyncService', () => {
});

test('test auto sync with sync resource change triggers sync for every change', async () => {
await runWithFakedTimers({ useSetImmediate: true }, async () => {
await runWithFakedTimers({}, async () => {
// Setup the client
const target = new UserDataSyncTestServer();
const client = disposableStore.add(new UserDataSyncClient(target));
Expand Down Expand Up @@ -85,7 +85,7 @@ suite('UserDataAutoSyncService', () => {
});

test('test auto sync with non sync resource change triggers sync', async () => {
await runWithFakedTimers({ useSetImmediate: true }, async () => {
await runWithFakedTimers({}, async () => {
// Setup the client
const target = new UserDataSyncTestServer();
const client = disposableStore.add(new UserDataSyncClient(target));
Expand All @@ -109,7 +109,7 @@ suite('UserDataAutoSyncService', () => {
});

test('test auto sync with non sync resource change does not trigger continuous syncs', async () => {
await runWithFakedTimers({ useSetImmediate: true }, async () => {
await runWithFakedTimers({}, async () => {
// Setup the client
const target = new UserDataSyncTestServer();
const client = disposableStore.add(new UserDataSyncClient(target));
Expand All @@ -135,7 +135,7 @@ suite('UserDataAutoSyncService', () => {
});

test('test first auto sync requests', async () => {
await runWithFakedTimers({ useSetImmediate: true }, async () => {
await runWithFakedTimers({}, async () => {
// Setup the client
const target = new UserDataSyncTestServer();
const client = disposableStore.add(new UserDataSyncClient(target));
Expand Down Expand Up @@ -175,7 +175,7 @@ suite('UserDataAutoSyncService', () => {
});

test('test further auto sync requests without changes', async () => {
await runWithFakedTimers({ useSetImmediate: true }, async () => {
await runWithFakedTimers({}, async () => {
// Setup the client
const target = new UserDataSyncTestServer();
const client = disposableStore.add(new UserDataSyncClient(target));
Expand All @@ -196,7 +196,7 @@ suite('UserDataAutoSyncService', () => {
});

test('test further auto sync requests with changes', async () => {
await runWithFakedTimers({ useSetImmediate: true }, async () => {
await runWithFakedTimers({}, async () => {
// Setup the client
const target = new UserDataSyncTestServer();
const client = disposableStore.add(new UserDataSyncClient(target));
Expand Down Expand Up @@ -233,7 +233,7 @@ suite('UserDataAutoSyncService', () => {
});

test('test auto sync send execution id header', async () => {
await runWithFakedTimers({ useSetImmediate: true }, async () => {
await runWithFakedTimers({}, async () => {
// Setup the client
const target = new UserDataSyncTestServer();
const client = disposableStore.add(new UserDataSyncClient(target));
Expand All @@ -258,7 +258,7 @@ suite('UserDataAutoSyncService', () => {
});

test('test delete on one client throws turned off error on other client while syncing', async () => {
await runWithFakedTimers({ useSetImmediate: true }, async () => {
await runWithFakedTimers({}, async () => {
const target = new UserDataSyncTestServer();

// Set up and sync from the client
Expand Down Expand Up @@ -294,7 +294,7 @@ suite('UserDataAutoSyncService', () => {
});

test('test disabling the machine turns off sync', async () => {
await runWithFakedTimers({ useSetImmediate: true }, async () => {
await runWithFakedTimers({}, async () => {
const target = new UserDataSyncTestServer();

// Set up and sync from the test client
Expand Down Expand Up @@ -328,7 +328,7 @@ suite('UserDataAutoSyncService', () => {
});

test('test removing the machine adds machine back', async () => {
await runWithFakedTimers({ useSetImmediate: true }, async () => {
await runWithFakedTimers({}, async () => {
const target = new UserDataSyncTestServer();

// Set up and sync from the test client
Expand All @@ -353,7 +353,7 @@ suite('UserDataAutoSyncService', () => {
});

test('test creating new session from one client throws session expired error on another client while syncing', async () => {
await runWithFakedTimers({ useSetImmediate: true }, async () => {
await runWithFakedTimers({}, async () => {
const target = new UserDataSyncTestServer();

// Set up and sync from the client
Expand Down Expand Up @@ -392,7 +392,7 @@ suite('UserDataAutoSyncService', () => {
});

test('test rate limit on server', async () => {
await runWithFakedTimers({ useSetImmediate: true }, async () => {
await runWithFakedTimers({}, async () => {
const target = new UserDataSyncTestServer(5);

// Set up and sync from the test client
Expand All @@ -412,7 +412,7 @@ suite('UserDataAutoSyncService', () => {
});

test('test auto sync is suspended when server donot accepts requests', async () => {
await runWithFakedTimers({ useSetImmediate: true }, async () => {
await runWithFakedTimers({}, async () => {
const target = new UserDataSyncTestServer(5, 1);

// Set up and sync from the test client
Expand All @@ -432,7 +432,7 @@ suite('UserDataAutoSyncService', () => {
});

test('test cache control header with no cache is sent when triggered with disable cache option', async () => {
await runWithFakedTimers({ useSetImmediate: true }, async () => {
await runWithFakedTimers({}, async () => {
const target = new UserDataSyncTestServer(5, 1);

// Set up and sync from the test client
Expand All @@ -446,7 +446,7 @@ suite('UserDataAutoSyncService', () => {
});

test('test cache control header is not sent when triggered without disable cache option', async () => {
await runWithFakedTimers({ useSetImmediate: true }, async () => {
await runWithFakedTimers({}, async () => {
const target = new UserDataSyncTestServer(5, 1);

// Set up and sync from the test client
Expand Down
17 changes: 12 additions & 5 deletions test/unit/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,22 @@ async function runTestsInBrowser(testModules, browserType) {
withReporter(browserType, new EchoRunner(emitter, browserType.toUpperCase()));

// collection failures for console printing
const fails = [];
const failingModuleIds = [];
const failingTests = [];
emitter.on('fail', (test, err) => {
if (err.stack) {
const regex = /(vs\/.*\.test)\.js/;
for (const line of String(err.stack).split('\n')) {
const match = regex.exec(line);
if (match) {
fails.push(match[1]);
break;
failingModuleIds.push(match[1]);
return;
}
}
}

// We could not determine the module id
failingTests.push(test.fullTitle);
});

try {
Expand All @@ -172,8 +176,11 @@ async function runTestsInBrowser(testModules, browserType) {
}
await browser.close();

if (fails.length > 0) {
return `to DEBUG, open ${browserType.toUpperCase()} and navigate to ${target.href}?${fails.map(module => `m=${module}`).join('&')}`;
if (failingModuleIds.length > 0) {
return `to DEBUG, open ${browserType.toUpperCase()} and navigate to ${target.href}?${failingModuleIds.map(module => `m=${module}`).join('&')}`;
}
if (failingTests.length > 0) {
return `The followings tests are failing:\n - ${failingTests.join('\n - ')}`;
}
}

Expand Down

0 comments on commit 3530e85

Please sign in to comment.