Skip to content

Commit 43709e9

Browse files
committed
tests,ci: add a retry loop for the tasks done by vlib/v/compiler_errors_test.v, to reduce false positives for alpine-docker-musl-gcc
1 parent e8ce02b commit 43709e9

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

vlib/v/compiler_errors_test.v

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ mut:
6363
found___ string
6464
took time.Duration
6565
cli_cmd string
66+
ntries int
67+
max_ntries int = 1
6668
}
6769

6870
struct Tasks {
@@ -186,6 +188,7 @@ fn (mut tasks Tasks) add(custom_vexe string, dir string, voptions string, result
186188
}
187189

188190
fn (mut tasks Tasks) add_evars(evars string, custom_vexe string, dir string, voptions string, result_extension string, tests []string, is_module bool) {
191+
max_ntries := get_max_ntries()
189192
paths := vtest.filter_vtest_only(tests, basepath: dir)
190193
for path in paths {
191194
tasks.all << TaskDescription{
@@ -196,6 +199,7 @@ fn (mut tasks Tasks) add_evars(evars string, custom_vexe string, dir string, vop
196199
result_extension: result_extension
197200
path: path
198201
is_module: is_module
202+
max_ntries: max_ntries
199203
}
200204
}
201205
}
@@ -316,23 +320,40 @@ fn (mut tasks Tasks) run() {
316320
fn work_processor(work chan TaskDescription, results chan TaskDescription) {
317321
for {
318322
mut task := <-work or { break }
319-
sw := time.new_stopwatch()
320-
task.execute()
321-
task.took = sw.elapsed()
323+
mut i := 0
324+
for i = 1; i <= task.max_ntries; i++ {
325+
sw := time.new_stopwatch()
326+
task.execute()
327+
task.took = sw.elapsed()
328+
if !task.is_error {
329+
break
330+
}
331+
cli_cmd := task.get_cli_cmd()
332+
eprintln('> failed ${i:3} times, doing `${cli_cmd}`\n')
333+
if i <= task.max_ntries {
334+
time.sleep(100 * time.millisecond)
335+
}
336+
}
337+
task.ntries = i
322338
results <- task
323339
}
324340
}
325341

342+
fn (mut task TaskDescription) get_cli_cmd() string {
343+
program := task.path
344+
cmd_prefix := if task.evars.len > 0 { '${task.evars} ' } else { '' }
345+
cli_cmd := '${cmd_prefix}${os.quoted_path(task.vexe)} ${task.voptions} ${os.quoted_path(program)}'
346+
return cli_cmd
347+
}
348+
326349
// actual processing; Note: no output is done here at all
327350
fn (mut task TaskDescription) execute() {
328351
if task.is_skipped {
329352
return
330353
}
331-
program := task.path
332-
cmd_prefix := if task.evars.len > 0 { '${task.evars} ' } else { '' }
333-
cli_cmd := '${cmd_prefix}${os.quoted_path(task.vexe)} ${task.voptions} ${os.quoted_path(program)}'
354+
cli_cmd := task.get_cli_cmd()
334355
res := os.execute(cli_cmd)
335-
expected_out_path := program.replace('.vv', '') + task.result_extension
356+
expected_out_path := task.path.replace('.vv', '') + task.result_extension
336357
task.expected_out_path = expected_out_path
337358
task.cli_cmd = cli_cmd
338359
if should_autofix && !os.exists(expected_out_path) {
@@ -381,3 +402,7 @@ fn get_tests_in_dir(dir string, is_module bool) []string {
381402
tests.sort()
382403
return tests
383404
}
405+
406+
fn get_max_ntries() int {
407+
return if v_ci_musl { 3 } else { 1 }
408+
}

0 commit comments

Comments
 (0)