Skip to content

Commit

Permalink
Tests for nested try-retry
Browse files Browse the repository at this point in the history
  • Loading branch information
aajanki committed Jan 6, 2025
1 parent d8c1f31 commit 430dabd
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions test/transpiler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2558,6 +2558,100 @@ describe('Try-catch-finally statement', () => {
assertTranspiled(code, expected)
})

it('applies retry policy only on one try on nested try blocks', () => {
const code = `
function main() {
try {
const response = http.get("https://visit.dreamland.test/");
try {
const a = 1;
} catch (e) {}
} catch (e) {
log("Error!");
}
retry_policy(http.default_retry);
}`

const expected = `
main:
steps:
- try1:
try:
steps:
- call_http_get_1:
call: http.get
args:
url: https://visit.dreamland.test/
result: response
- try2:
try:
steps:
- assign1:
assign:
- a: 1
except:
as: e
steps: []
retry: \${http.default_retry}
except:
as: e
steps:
- assign2:
assign:
- __temp: \${log("Error!")}
`

assertTranspiled(code, expected)
})

it('applies separate retry policies on nested try blocks', () => {
const code = `
function main() {
try {
const response = http.get("https://visit.dreamland.test/");
try {
const a = 1;
} catch (e) {}
retry_policy(custom_retry);
} catch (e) {
log("Error!");
}
retry_policy(http.default_retry);
}`

const expected = `
main:
steps:
- try1:
try:
steps:
- call_http_get_1:
call: http.get
args:
url: https://visit.dreamland.test/
result: response
- try2:
try:
steps:
- assign1:
assign:
- a: 1
retry: \${custom_retry}
except:
as: e
steps: []
retry: \${http.default_retry}
except:
as: e
steps:
- assign2:
assign:
- __temp: \${log("Error!")}
`

assertTranspiled(code, expected)
})

it('throws if retry is called without arguments', () => {
const code = `
function main() {
Expand Down

0 comments on commit 430dabd

Please sign in to comment.