Skip to content

Commit

Permalink
fix timeout test and add actual to expect
Browse files Browse the repository at this point in the history
  • Loading branch information
tsuf239 committed Jul 1, 2024
1 parent 75d8bd3 commit 0d9fb18
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions examples/tests/sdk_tests/function/timeout.test.w
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
bring cloud;
bring util;
bring expect;

let c = new cloud.Counter();

let ERROR_MSG_BY_TARGET: Map<str> = {"tf-gcp": "upstream request timeout"};
let timeoutError = ERROR_MSG_BY_TARGET.tryGet(util.env("WING_TARGET")) ?? "Function timed out";
let TIMEOUT_BY_TARGET: Map<num> = {"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();
}, timeout: 1s) as "function with 1s timeout";

// 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";

Expand All @@ -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 = "";
Expand All @@ -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";
2 changes: 1 addition & 1 deletion libs/wingsdk/src/expect/expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
});
}
}
Expand Down

0 comments on commit 0d9fb18

Please sign in to comment.