Skip to content

Commit

Permalink
fix(ci): proper random generation on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
mookums committed Mar 6, 2025
1 parent 54f2ecf commit f46cea0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
- name: Generate random 64-bit integer
id: random
shell: bash
run: echo "RANDOM_INT=$(shuf -i 1-9223372036854775807 -n 1)" >> $GITHUB_ENV
run: echo "RANDOM_INT=$((RANDOM + (RANDOM << 15) + (RANDOM << 30) + (RANDOM << 45)))" >> $GITHUB_ENV
- name: Run E2E tests with ${{ matrix.async }}
run: zig build -Dasync=${{ matrix.async }} test_e2e -- ${{ env.RANDOM_INT }}

Expand Down
19 changes: 5 additions & 14 deletions test/e2e/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,20 @@ pub fn main() !void {
defer allocator.free(bytes);

var iter = std.mem.splitScalar(u8, bytes, '\n');
const pre_new = iter.next() orelse {
return log.err("seed not passed in: ./e2e [seed]", .{});
};
const not_passed_in = "seed not passed in: ./e2e [seed]";
const pre_new = iter.next() orelse @panic(not_passed_in);
const length = pre_new.len;

if (length <= 1) {
return log.err("seed not passed in: ./e2e [seed]", .{});
}

if (length >= maybe_seed_buffer.len) {
return log.err("seed too long to be a u64", .{});
}
if (length <= 1) @panic(not_passed_in);
if (length >= maybe_seed_buffer.len) @panic("seed too long to be a u64");

assert(length < maybe_seed_buffer.len);
std.mem.copyForwards(u8, &maybe_seed_buffer, pre_new);
maybe_seed_buffer[length] = 0;
break :blk maybe_seed_buffer[0..length :0];
};

const seed = std.fmt.parseUnsigned(u64, seed_string, 10) catch {
log.err("seed passed in is not u64", .{});
return;
};
const seed = std.fmt.parseUnsigned(u64, seed_string, 10) catch @panic("seed passed in is not u64");
var prng = std.Random.DefaultPrng.init(seed);
const rand = prng.random();

Expand Down

0 comments on commit f46cea0

Please sign in to comment.