diff --git a/examples/tests/sdk_tests/function/timeout.test.w b/examples/tests/sdk_tests/function/timeout.test.w index cb4f14ffa90..cc1da9c7c3b 100644 --- a/examples/tests/sdk_tests/function/timeout.test.w +++ b/examples/tests/sdk_tests/function/timeout.test.w @@ -1,8 +1,14 @@ bring cloud; bring util; +bring expect; let c = new cloud.Counter(); +let ERROR_MSG_BY_TARGET: Map = {"tf-gcp": "upstream request timeout"}; +let timeoutError = ERROR_MSG_BY_TARGET.tryGet(util.env("WING_TARGET")) ?? "Function timed out"; +let TIMEOUT_BY_TARGET: Map = {"tf-gcp": 120}; +let timeoutValue = TIMEOUT_BY_TARGET.tryGet(util.env("WING_TARGET")) ?? 60; + let f1 = new cloud.Function(inflight () => { util.sleep(1.5s); c.inc(); @@ -10,9 +16,9 @@ let f1 = new cloud.Function(inflight () => { // testing the default timeout - should be 1 minute let f2 = new cloud.Function(inflight () => { - util.sleep(30s); + util.sleep(duration.fromSeconds(timeoutValue / 2)); c.inc(); - util.sleep(31s); + util.sleep(duration.fromSeconds(timeoutValue / 2 + 1)); c.inc(); }) as "function with default timeout"; @@ -24,7 +30,7 @@ new std.Test(inflight () => { e = error; } - assert(e.contains("Function timed out")); + expect.match(e, timeoutError); assert(c.peek() == 0); e = ""; @@ -34,6 +40,6 @@ new std.Test(inflight () => { e = error; } - assert(e.contains("Function timed out")); + expect.match(e, timeoutError); assert(c.peek() == 1); -}, timeout: 2m) as "function invoke throws on timeout"; +}, timeout: 4m) as "function invoke throws on timeout"; diff --git a/libs/wingsdk/src/expect/expect.ts b/libs/wingsdk/src/expect/expect.ts index 087f67cacb5..55196012a34 100644 --- a/libs/wingsdk/src/expect/expect.ts +++ b/libs/wingsdk/src/expect/expect.ts @@ -75,7 +75,7 @@ export class Util { const matches = regex.test(actual); if (!matches) { throw new nodeAssert.AssertionError({ - message: `The input did not match the regular expression ${expected}`, + message: `The input "${actual}" did not match the regular expression ${expected}`, }); } }