Skip to content

Commit

Permalink
fix: track counter in steps
Browse files Browse the repository at this point in the history
  • Loading branch information
CahidArda committed Nov 18, 2024
1 parent 6a6c038 commit 65015c6
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions examples/ci/app/test-routes/sleepWithoutAwait/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ type Invoice = {
type Charge = {
invoice: Invoice;
success: boolean;
counter: number
};

const header = `test-header-foo`
const headerValue = `header-bar`
const payload: Invoice = { date: 123, email: "[email protected]", amount: 10 }

let counter = 0;
const attemptCharge = () => {
const attemptCharge = (counter: number) => {
counter += 1;
if (counter === 3) {
counter = 0;
return true;
return { success: true, counter };
}
return false;
return { success: false, counter };
};

export const { POST, GET } = testServe(
Expand All @@ -36,13 +36,19 @@ export const { POST, GET } = testServe(
expect(typeof invoice, typeof payload);
expect(JSON.stringify(invoice), JSON.stringify(payload));

let charge: Charge = {
success: false,
counter: 0,
invoice
}

for (let index = 0; index < 3; index++) {
const charge = await context.run("attemptCharge", () => {
const success = attemptCharge();
const charge: Charge = { invoice, success };
return charge;
charge = await context.run("attemptCharge", () => {
const { success, counter } = attemptCharge(charge.counter);
const newCharge: Charge = { invoice, success, counter };
return newCharge;
});

if (charge.success) {
const [updateDb, receipt, sleepResult] = await Promise.all([
context.run("updateDb", () => {
Expand Down Expand Up @@ -82,4 +88,4 @@ export const { POST, GET } = testServe(
[ header ]: headerValue
}
}
)
)

0 comments on commit 65015c6

Please sign in to comment.