Skip to content

Commit 0f46984

Browse files
committed
Make tests fail quicker
1 parent 65695ea commit 0f46984

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

src/main.zig

+3-2
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ pub fn main() !void {
5353
}
5454

5555
const dir_path_relative = args.get("dir") orelse "/tmp/fpindex";
56-
const dir_path = try std.fs.cwd().realpathAlloc(allocator, dir_path_relative);
56+
const dir = try std.fs.cwd().makeOpenPath(dir_path_relative, .{ .iterate = true });
57+
58+
const dir_path = try dir.realpathAlloc(allocator, ".");
5759
defer allocator.free(dir_path);
5860

59-
const dir = try std.fs.cwd().makeOpenPath(dir_path, .{ .iterate = true });
6061
log.info("using directory {s}", .{dir_path});
6162

6263
const address = args.get("address") orelse "127.0.0.1";

tests/conftest.py

+23-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
from urllib.parse import urljoin
66

77

8+
class ServerNotReady(Exception):
9+
pass
10+
11+
12+
class ServerDied(Exception):
13+
pass
14+
15+
816
class ServerManager:
917

1018
def __init__(self, base_dir, port):
@@ -45,6 +53,10 @@ def restart(self, kill=True):
4553
self.stop(kill=kill)
4654
self.start()
4755

56+
def print_error_log(self):
57+
for line in self.error_log():
58+
print(line)
59+
4860
def wait_for_ready(self, index_name=None, timeout=10.0):
4961
deadline = time.time() + timeout
5062
while True:
@@ -55,12 +67,18 @@ def wait_for_ready(self, index_name=None, timeout=10.0):
5567
try:
5668
with requests.get(url) as res:
5769
res.raise_for_status()
70+
return
5871
except Exception:
5972
if time.time() > deadline:
60-
raise TimeoutError()
61-
time.sleep(timeout / 100.0)
62-
else:
63-
break
73+
self.print_error_log()
74+
raise ServerNotReady()
75+
try:
76+
self.process.wait(timeout / 100.0)
77+
except subprocess.TimeoutExpired:
78+
continue
79+
else:
80+
self.print_error_log()
81+
raise ServerDied()
6482

6583
def error_log(self):
6684
for line in self.log_file.read_text().splitlines():
@@ -75,8 +93,7 @@ def server(tmp_path_factory):
7593
yield srv
7694
finally:
7795
srv.stop()
78-
for line in srv.error_log():
79-
print(line)
96+
srv.print_error_log()
8097

8198

8299
index_no = 1

0 commit comments

Comments
 (0)