-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix unhandled promise rejections #702
Changes from all commits
be83e97
07af7fb
916a138
85a9fa5
1607174
ff9e916
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,15 +71,30 @@ suite('Unit Tests - debugging', () => { | |
assert.equal(tests.testFunctions.length, 2, 'Incorrect number of test functions'); | ||
assert.equal(tests.testSuites.length, 2, 'Incorrect number of test suites'); | ||
|
||
const deferred = createDeferred<string>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With using |
||
const testFunction = [tests.testFunctions[0].testFunction]; | ||
testManager.runTest(CommandSource.commandPalette, { testFunction }, false, true); | ||
const launched = await mockDebugLauncher.launched; | ||
assert.isTrue(launched, 'Debugger not launched'); | ||
const runningPromise = testManager.runTest(CommandSource.commandPalette, { testFunction }, false, true); | ||
|
||
// This promise should never resolve nor reject. | ||
runningPromise | ||
.then(() => deferred.reject('Debugger stopped when it shouldn\'t have')) | ||
.catch(error => deferred.reject(error)); | ||
|
||
mockDebugLauncher.launched | ||
.then((launched) => { | ||
if (launched) { | ||
deferred.resolve(''); | ||
} else { | ||
deferred.reject('Debugger not launched'); | ||
} | ||
}) .catch(error => deferred.reject(error)); | ||
|
||
await deferred.promise; | ||
} | ||
|
||
test('Debugger should start (unittest)', async () => { | ||
await updateSetting('unitTest.unittestArgs', ['-s=./tests', '-p=test_*.py'], rootWorkspaceUri, configTarget); | ||
await testStartingDebugger('unittest'); | ||
await testStartingDebugger('unittest'); | ||
}); | ||
|
||
test('Debugger should start (pytest)', async () => { | ||
|
@@ -105,9 +120,10 @@ suite('Unit Tests - debugging', () => { | |
const launched = await mockDebugLauncher.launched; | ||
assert.isTrue(launched, 'Debugger not launched'); | ||
|
||
testManager.discoverTests(CommandSource.commandPalette, true, true, true); | ||
|
||
const discoveryPromise = testManager.discoverTests(CommandSource.commandPalette, true, true, true); | ||
await expect(runningPromise).to.be.rejectedWith(CANCELLATION_REASON, 'Incorrect reason for ending the debugger'); | ||
ioc.dispose(); // will cancel test discovery | ||
await expect(discoveryPromise).to.be.rejectedWith(CANCELLATION_REASON, 'Incorrect reason for ending the debugger'); | ||
} | ||
|
||
test('Debugger should stop when user invokes a test discovery (unittest)', async () => { | ||
|
@@ -151,6 +167,7 @@ suite('Unit Tests - debugging', () => { | |
runningPromise | ||
.then(() => 'Debugger stopped when it shouldn\'t have') | ||
.catch(() => 'Debugger crashed when it shouldn\'t have') | ||
// tslint:disable-next-line: no-floating-promises | ||
.then(error => { | ||
deferred.reject(error); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import { expect, use } from 'chai'; | |
import * as chaiAsPromised from 'chai-as-promised'; | ||
import * as path from 'path'; | ||
import { Uri } from 'vscode'; | ||
import {createDeferred} from '../../client/common/helpers'; | ||
import { Product } from '../../client/common/types'; | ||
import { CANCELLATION_REASON, CommandSource, UNITTEST_PROVIDER } from '../../client/unittests/common/constants'; | ||
import { ITestDiscoveryService } from '../../client/unittests/common/types'; | ||
|
@@ -60,9 +61,23 @@ suite('Unit Tests Stopping Discovery and Runner', () => { | |
|
||
const discoveryPromise = mockTestManager.discoverTests(CommandSource.auto); | ||
mockTestManager.discoveryDeferred.resolve(EmptyTests); | ||
mockTestManager.runTest(CommandSource.ui); | ||
const runningPromise = mockTestManager.runTest(CommandSource.ui); | ||
const deferred = createDeferred<string>(); | ||
|
||
await expect(discoveryPromise).to.eventually.equal(EmptyTests); | ||
// This promise should never resolve nor reject. | ||
runningPromise | ||
.then(() => Promise.reject('Debugger stopped when it shouldn\'t have')) | ||
.catch(error => deferred.reject(error)); | ||
|
||
discoveryPromise.then(result => { | ||
if (result === EmptyTests) { | ||
deferred.resolve(''); | ||
} else { | ||
deferred.reject('tests not empty'); | ||
} | ||
}).catch(error => deferred.reject(error)); | ||
|
||
await deferred.promise; | ||
}); | ||
|
||
test('Discovering tests should stop running tests', async () => { | ||
|
@@ -75,7 +90,7 @@ suite('Unit Tests Stopping Discovery and Runner', () => { | |
await new Promise(resolve => setTimeout(resolve, 1000)); | ||
|
||
// User manually discovering tests will kill the existing test runner. | ||
mockTestManager.discoverTests(CommandSource.ui, true, false, true); | ||
await mockTestManager.discoverTests(CommandSource.ui, true, false, true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This caused the coverage to go down because, without the |
||
await expect(runPromise).to.eventually.be.rejectedWith(CANCELLATION_REASON); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forEach
on an async function doesn't do anything.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see below for the fix to this entire test