Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
wip: use built-in attempt count
Browse files Browse the repository at this point in the history
  • Loading branch information
Noah Negin-Ulster committed Aug 19, 2022
1 parent 2ee14dd commit 0e49a47
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
21 changes: 11 additions & 10 deletions packages/client/src/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import { downloadFile } from './utils/downloadFile'
import { printTestSummary } from './utils/printTestSummary'
import { parseStatus } from './utils/status'

class RetryableError extends Error {}

async function runTest({
config,
filename,
Expand All @@ -41,30 +43,29 @@ async function runTest({
logger.verbose(`[${invokeBackend.BackendName}] [${executionId}] Running: '${filename}'`)
let status: TestStatus | null = null
try {
let retryCount = 0
const result = await retry(
async () => {
const invokeResult = await invokeBackend.invoke({
const { result } = await retry(
async (_, attempt) => {
const result = await invokeBackend.invoke({
config: {
...config,
retryCount: 0, // client will take care of retrying
// client will take care of retrying, so we disable retrying in the service
retryCount: 0,
},
filename,
code,
executionId,
})
status = parseStatus(result)
if (
retryCount !== config.retryCount &&
(status === TestStatus.Error || status === TestStatus.Failed)
(status === TestStatus.Error || status === TestStatus.Failed) &&
attempt <= config.retryCount
) {
throw new Error('Test failed. Retry triggered.')
throw new RetryableError()
}
return invokeResult
return { result, attempt }
},
{
retries: config.retryCount,
onRetry: () => void retryCount++,
},
)
return result
Expand Down
24 changes: 9 additions & 15 deletions packages/service/src/core/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function runTest(runTestContext: RunTestContext): Promise<InvokeRes
'sanity_runner.max_retry_count': runTestContext.maxRetryCount,
})

let retryCount = 0
const retryCount = 0
try {
await runner.writeTestCodeToDisk({ testCode: runTestContext.testCode })

Expand All @@ -46,18 +46,15 @@ export async function runTest(runTestContext: RunTestContext): Promise<InvokeRes
}

const results = await retry(
async () => {
logger.info(
`Starting test run (${retryCount + 1}/${runTestContext.maxRetryCount + 1}):`,
{
run_id: runTestContext.runId,
execution_id: runTestContext.executionId,
test_file: runTestContext.testFilename,
},
)
async (_, attempt) => {
logger.info(`Starting test run (${attempt}/${runTestContext.maxRetryCount + 1}):`, {
run_id: runTestContext.runId,
execution_id: runTestContext.executionId,
test_file: runTestContext.testFilename,
})
const result = await trace('Test Run', async (span) => {
span?.addTags({
'sanity_runner.attempt': retryCount + 1,
'sanity_runner.attempt': attempt,
'sanity_runner.runner': runner.name,
})
return await runner.run()
Expand All @@ -66,7 +63,7 @@ export async function runTest(runTestContext: RunTestContext): Promise<InvokeRes
// force retry if test was unsuccesfull
// if last retry, return as normal
if (!result.success) {
if (retryCount !== runTestContext.maxRetryCount) {
if (attempt <= runTestContext.maxRetryCount) {
throw new Error('Test Failed!')
}

Expand All @@ -80,9 +77,6 @@ export async function runTest(runTestContext: RunTestContext): Promise<InvokeRes
},
{
retries: runTestContext.maxRetryCount,
onRetry: function () {
retryCount++
},
},
)

Expand Down

0 comments on commit 0e49a47

Please sign in to comment.