Skip to content

Commit c2657a5

Browse files
committed
Reduce likelihood of false negative tests on slow file writes in Win + Mac CI matrix
1 parent 2a4a783 commit c2657a5

File tree

7 files changed

+28
-16
lines changed

7 files changed

+28
-16
lines changed

test/integration/lambda-termination-test.js

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
let test = require('tape')
22
let { existsSync, mkdirSync, readdirSync, rmSync } = require('fs')
33
let { join } = require('path')
4+
let chokidar = require('chokidar')
45
let sandbox = require('../../src')
56
let mock = join(process.cwd(), 'test', 'mock')
67
let { run, startup, shutdown } = require('../utils')
@@ -9,7 +10,7 @@ let fileThatShouldNotBeWritten = join(tmp, 'do-not-write-me')
910
let payload = { path: fileThatShouldNotBeWritten }
1011
let eventsPort = 4444
1112
let timeout = 1250
12-
let arc
13+
let arc, watcher
1314

1415
// Because these tests are firing Arc Functions events, that module needs a `ARC_EVENTS_PORT` env var to run locally
1516
// That said, to prevent side-effects, destroy that env var immediately after use
@@ -26,12 +27,12 @@ function reset (t) {
2627
delete process.env.ARC_ENV
2728
delete process.env.ARC_SANDBOX
2829
}
29-
function check (t) {
30+
function check (t, altTimeout) {
3031
setTimeout(() => {
3132
console.log('Files in tmp:', readdirSync(tmp))
3233
t.notOk(existsSync(fileThatShouldNotBeWritten), 'File not created as event timed out and process was terminated appropriately')
3334
reset(t)
34-
}, timeout)
35+
}, altTimeout || timeout)
3536
}
3637

3738
test('Set up env', t => {
@@ -59,17 +60,32 @@ function runTests (runType, t) {
5960
t.plan(3)
6061
setup(t)
6162
let fine = join(tmp, 'fine-write-me')
63+
let timer
64+
65+
watcher = chokidar.watch(tmp)
66+
watcher.on('add', function (added) {
67+
if (added === fine) {
68+
clearTimeout(timer)
69+
watcher.close().then(() => {
70+
console.log('Files in tmp:', readdirSync(tmp))
71+
t.pass('File successfully created by event as event did not time out')
72+
reset(t)
73+
})
74+
}
75+
})
76+
6277
arc.events.publish({
6378
name: 'event-does-not-timeout',
6479
payload: { path: fine }
6580
},
6681
function done (err) {
6782
if (err) t.fail(err)
68-
else setTimeout(() => {
69-
console.log('Files in tmp:', readdirSync(tmp))
70-
t.ok(existsSync(fine), 'File successfully created by event as event did not time out')
71-
reset(t)
72-
}, 1000)
83+
else {
84+
let ohno = 10000
85+
timer = setTimeout(() => {
86+
t.fail(`Did not write file in ${ohno}ms, sigh`)
87+
}, ohno)
88+
}
7389
})
7490
})
7591

@@ -148,7 +164,7 @@ function runTests (runType, t) {
148164
},
149165
function done (err) {
150166
if (err) t.fail(err)
151-
else check(t)
167+
else check(t, 600)
152168
})
153169
})
154170

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
@aws
2-
timeout 1
2+
timeout 5

test/mock/lambda-termination/src/events/event-timeout-async-child/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ let { spawnSync } = require('child_process')
44
exports.handler = async (event) => {
55
event = JSON.parse(event.Records[0].Sns.Message)
66
let pathToFile = event.path
7-
87
let timeout = '1.25' // this event is configured to time out after 1s (see config.arc), so we'll sleep longer
98
console.log(`event-timeout-async-child will write to ${pathToFile} in ${timeout}s...`)
109
// this should sleep but be terminated before getting to echo as timeout is set to 1 sec in config.arc

test/mock/lambda-termination/src/events/event-timeout-async-settimeout/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ let { join } = require('path')
44
exports.handler = async (event) => {
55
event = JSON.parse(event.Records[0].Sns.Message)
66
let pathToFile = event.path
7-
let timeout = 1250 // this event is configured to time out after 1s (see config.arc), so lets setTimeout longer
7+
let timeout = 1250 // this event is configured to time out after 1s (see config.arc), so let's setTimeout longer
88
console.log(`event-timeout-async-settimeout will write to ${pathToFile} in ${timeout}ms...`)
99
setTimeout(() => {
1010
// this should never execute as timeout is set to 1 sec in config.arc

test/mock/lambda-termination/src/events/event-timeout-async/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ let { join } = require('path')
44
exports.handler = async (event) => {
55
event = JSON.parse(event.Records[0].Sns.Message)
66
let pathToFile = event.path
7-
87
let timeout = 1250 // this event is configured to time out after 1s (see config.arc), so we'll setTimeout longer
98
console.log(`event-timeout-async will write to ${pathToFile} in ${timeout}ms...`)
109
await new Promise(resolve => setTimeout(resolve, timeout))

test/mock/lambda-termination/src/events/event-timeout-sync-child/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ let { spawnSync } = require('child_process')
44
exports.handler = (event, context, callback) => {
55
event = JSON.parse(event.Records[0].Sns.Message)
66
let pathToFile = event.path
7-
87
let timeout = '1.25' // this event is configured to time out after 1s (see config.arc), so we'll sleep longer
98
console.log(`event-timeout-sync-child will write to ${pathToFile} in ${timeout}s...`)
109
// this should sleep but be terminated before getting to echo as timeout is set to 1 sec in config.arc

test/mock/lambda-termination/src/events/event-timeout-sync/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ let { join } = require('path')
44
exports.handler = (event, context, callback) => {
55
event = JSON.parse(event.Records[0].Sns.Message)
66
let pathToFile = event.path
7-
8-
let timeout = 1250 // this event is configured to time out after 1s (see config.arc), so lets setTimeout longer
7+
let timeout = 1250 // this event is configured to time out after 1s (see config.arc), so let's setTimeout longer
98
console.log(`event-timeout-sync will write to ${pathToFile} in ${timeout}ms...`)
109
setTimeout(() => {
1110
// this should never execute as timeout is set to 1 sec in config.arc

0 commit comments

Comments
 (0)