| ... | @@ -1124,17 +1124,31 @@ test "open file with exclusive lock twice, make sure second lock waits" { | ... | @@ -1124,17 +1124,31 @@ test "open file with exclusive lock twice, make sure second lock waits" { |
| 1124 | test "open file with exclusive nonblocking lock twice (absolute paths)" { | 1124 | test "open file with exclusive nonblocking lock twice (absolute paths)" { |
| 1125 | if (builtin.os.tag == .wasi) return error.SkipZigTest; | 1125 | if (builtin.os.tag == .wasi) return error.SkipZigTest; |
| 1126 | | 1126 | |
| 1127 | const allocator = testing.allocator; | 1127 | var random_bytes: [12]u8 = undefined; |
| | 1128 | std.crypto.random.bytes(&random_bytes); |
| 1128 | | 1129 | |
| 1129 | const cwd = try std.process.getCwdAlloc(allocator); | 1130 | var random_b64: [fs.base64_encoder.calcSize(random_bytes.len)]u8 = undefined; |
| 1130 | defer allocator.free(cwd); | 1131 | _ = fs.base64_encoder.encode(&random_b64, &random_bytes); |
| 1131 | const file_paths: [2][]const u8 = .{ cwd, "zig-test-absolute-paths.txt" }; | | |
| 1132 | const filename = try fs.path.resolve(allocator, &file_paths); | | |
| 1133 | defer allocator.free(filename); | | |
| 1134 | | 1132 | |
| 1135 | const file1 = try fs.createFileAbsolute(filename, .{ .lock = .Exclusive, .lock_nonblocking = true }); | 1133 | const sub_path = random_b64 ++ "-zig-test-absolute-paths.txt"; |
| 1136 | | 1134 | |
| 1137 | const file2 = fs.createFileAbsolute(filename, .{ .lock = .Exclusive, .lock_nonblocking = true }); | 1135 | const gpa = testing.allocator; |
| | 1136 | |
| | 1137 | const cwd = try std.process.getCwdAlloc(gpa); |
| | 1138 | defer gpa.free(cwd); |
| | 1139 | |
| | 1140 | const filename = try fs.path.resolve(gpa, &[_][]const u8{ cwd, sub_path }); |
| | 1141 | defer gpa.free(filename); |
| | 1142 | |
| | 1143 | const file1 = try fs.createFileAbsolute(filename, .{ |
| | 1144 | .lock = .Exclusive, |
| | 1145 | .lock_nonblocking = true, |
| | 1146 | }); |
| | 1147 | |
| | 1148 | const file2 = fs.createFileAbsolute(filename, .{ |
| | 1149 | .lock = .Exclusive, |
| | 1150 | .lock_nonblocking = true, |
| | 1151 | }); |
| 1138 | file1.close(); | 1152 | file1.close(); |
| 1139 | try testing.expectError(error.WouldBlock, file2); | 1153 | try testing.expectError(error.WouldBlock, file2); |
| 1140 | | 1154 | |