Skip to content

Commit

Permalink
test: fix flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards1211 committed Aug 18, 2021
1 parent d6cb07d commit 778fffe
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
"sinon": "^4.1.2",
"typescript": "^4.1.3",
"validate-commit-msg": "^2.11.1",
"waait": "^1.0.5",
"webpack": "^3.8.1"
},
"dependencies": {
Expand Down
13 changes: 9 additions & 4 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { RuntimeTypeError } from 'typed-validators'
import Promake from '../src'
import TestResource from './TestResource'
import poll from '@jcoreio/poll'
import delay from 'waait'

describe('Promake', () => {
describe('.task', () => {
Expand Down Expand Up @@ -451,7 +452,7 @@ Tasks:
expect(stdout).to.match(/^\s*$/m)
expect(stderr).to.match(/^\s*$/m)
})
it(`forwards SIGINT and waits for children to exit`, async function () {
it.only(`forwards SIGINT and waits for children to exit`, async function () {
const tmpDir = path.join(os.tmpdir(), `promake-${Math.random()}`)
await fs.mkdirs(tmpDir)
const files = ['file1.txt', 'file2.txt'].map((file) =>
Expand All @@ -478,15 +479,15 @@ Tasks:
).to.be.false
}
})
it(`on second SIGINT, kills children with SIGKILL`, async function () {
it.only(`on second SIGINT, kills children with SIGKILL`, async function () {
const tmpDir = path.join(os.tmpdir(), `promake-${Math.random()}`)
await fs.mkdirs(tmpDir)
const files = ['file1.txt', 'file2.txt'].map((file) =>
path.join(tmpDir, file)
)
const child = spawn(
'babel-node',
[promake, 'sigintTest', '--', ...files],
[promake, 'sigintTest', '--', '--hang', ...files],
{ stdio: 'inherit' }
)
await poll(async () => {
Expand All @@ -497,7 +498,11 @@ Tasks:
).to.be.true
}
}, 50).timeout(10000)
await Promise.all([child, child.kill('SIGINT'), child.kill('SIGINT')])
await Promise.all([
child,
child.kill('SIGINT'),
delay(50).then(() => child.kill('SIGINT')),
])
for (const file of files) {
expect(
await fs.exists(file),
Expand Down
23 changes: 13 additions & 10 deletions test/integration/promake
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#!/usr/bin/env babel-node
// @flow

process.chdir(__dirname)

const Promake = require('../../src')
const glob = require('glob').sync
const fs = require('fs-extra')
const os = require('os')
const path = require('path')

const serverSourceFiles = glob('src/server/**/*.js')
const serverBuildFiles = serverSourceFiles.map((file) =>
Expand Down Expand Up @@ -57,14 +54,20 @@ task('build:ci', [

task('clean', () => fs.remove('build')).description('remove all build output')

task('sigintTest', ({ args }) =>
Promise.all(
args.map((file) =>
spawn(process.execPath, [require.resolve('./sigintTest.js'), file], {
stdio: 'inherit',
})
task('sigintTest', async ({ args }) => {
const files = args.filter((a) => !a.startsWith('-'))
const otherArgs = args.filter((a) => a.startsWith('-'))
await Promise.all(
files.map((file) =>
spawn(
process.execPath,
[require.resolve('./sigintTest.js'), file, ...otherArgs],
{
stdio: 'inherit',
}
)
)
)
)
})

cli()
2 changes: 1 addition & 1 deletion test/integration/sigintTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ fs.writeFileSync(file, `${__filename}:${new Date().toISOString()}`, 'utf8')
const timeout = setTimeout(() => {}, 60000)

process.on('SIGINT', async () => {
if (process.argv.indexOf('--hang') >= 0) return
clearTimeout(timeout)
await new Promise((resolve) => setTimeout(resolve, 3000))
fs.unlinkSync(file)
process.exit(0)
})
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9948,6 +9948,11 @@ vue-eslint-parser@~7.1.0:
esquery "^1.0.1"
lodash "^4.17.15"

waait@^1.0.5:
version "1.0.5"
resolved "https://registry.npmjs.org/waait/-/waait-1.0.5.tgz#6a3c7aaa88bd0a1a545e9d47890b9595bebf9aa7"
integrity sha512-wp+unA4CpqxvBUKHHv8D86fK4jWByHAWyhEXXVHfVUZfK+16ylpj7hjQ58Z8j9ntu8XNukRQT8Fi5qbyJ8rkyw==

watchpack@^1.4.0:
version "1.4.0"
resolved "https://registry.npmjs.org/watchpack/-/watchpack-1.4.0.tgz#4a1472bcbb952bd0a9bb4036801f954dfb39faac"
Expand Down

0 comments on commit 778fffe

Please sign in to comment.