@@ -2403,6 +2403,36 @@ test "set executable bit based on file content" {
24032403 // -rwxrwxr-x 1 17 Apr script_with_shebang_without_exec_bit
24042404}
24052405
2406+ test "retry delay override works and resets after use" {
2407+ var retry = Retry { .cur_retries = 1 };
2408+
2409+ // test simple case
2410+ try std .testing .expectEqual (3000 , retry .calcRetryDelayMs ());
2411+
2412+ // test override works and gets reset to `null`
2413+ retry .retry_delay_override_ms = 500 ;
2414+ try std .testing .expectEqual (500 , retry .calcRetryDelayMs ());
2415+ try std .testing .expectEqual (null , retry .retry_delay_override_ms );
2416+ }
2417+
2418+ test "retries the correct number of times" {
2419+ // non spurious error
2420+ var retry = Retry { .retry_delay_override_ms = 1 };
2421+ try std .testing .expectError (error .NonSpurious , retry .callWithRetries (@TypeOf (testFnToCallWithRetries ), testFnToCallWithRetries , .{ & retry , false }));
2422+ try std .testing .expectEqual (0 , retry .cur_retries );
2423+
2424+ // spurious error
2425+ retry = Retry { .retry_delay_override_ms = 1 };
2426+ try std .testing .expectError (error .MaybeSpurious , retry .callWithRetries (@TypeOf (testFnToCallWithRetries ), testFnToCallWithRetries , .{ & retry , true }));
2427+ try std .testing .expectEqual (retry .max_retries , retry .cur_retries );
2428+ }
2429+
2430+ fn testFnToCallWithRetries (r : * Retry , is_spurious_error : bool ) ! void {
2431+ // set to 1 ms so the unit test doesn't take forever
2432+ r .retry_delay_override_ms = 1 ;
2433+ return if (is_spurious_error ) error .MaybeSpurious else error .NonSpurious ;
2434+ }
2435+
24062436fn saveEmbedFile (comptime tarball_name : []const u8 , dir : fs.Dir ) ! void {
24072437 //const tarball_name = "duplicate_paths_excluded.tar.gz";
24082438 const tarball_content = @embedFile ("Fetch/testdata/" ++ tarball_name );
0 commit comments