Skip to content

Commit d6ccf18

Browse files
authored
Merge pull request #353 from hhugo/fix-272
Do not use symlink when writing and reading log files.
2 parents 75f6336 + 12ecd24 commit d6ccf18

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

Diff for: CHANGES.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
### dev
2+
3+
- Fix a bug when running test concurently. Alcotest could fail to
4+
output the content of the log file. (#353, @hhugo)
5+
16
### 1.5.0 (2021-10-09)
27

38
- Make Alcotest compatible with `js_of_ocaml.3.11.0`. Users can depend on the

Diff for: src/alcotest-engine/log_trap.ml

+19-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ module Make
99
struct
1010
open Promise.Syntax
1111

12-
type state = { root : string; uuid : string; suite_name : string }
12+
type state = {
13+
root : string;
14+
uuid : string;
15+
suite_name : string;
16+
has_alias : bool;
17+
}
18+
1319
type t = Inactive | Active of state
1420

1521
(** Take a string path and collapse a leading [$HOME] path segment to [~]. *)
@@ -30,7 +36,8 @@ struct
3036

3137
let active ~root ~uuid ~suite_name =
3238
Platform.prepare_log_trap ~root ~uuid ~name:suite_name;
33-
Active { root; uuid; suite_name }
39+
let has_alias = Platform.file_exists (Filename.concat root suite_name) in
40+
Active { root; uuid; suite_name; has_alias }
3441

3542
let pp_path = Fmt.using maybe_collapse_home Fmt.string
3643

@@ -63,31 +70,31 @@ struct
6370
in
6471
ListLabels.iter display_lines ~f:(Fmt.pf ppf "%s@\n")
6572

66-
let log_dir { suite_name; uuid; root } =
67-
(* We don't create symlinks on Windows. *)
68-
let via_symlink = not Sys.win32 in
73+
let log_dir ~via_symlink { suite_name; uuid; root; has_alias } =
74+
let via_symlink = via_symlink && has_alias in
6975
Filename.concat root (if via_symlink then suite_name else uuid)
7076

71-
let output_fpath t tname = Filename.concat (log_dir t) (Test_name.file tname)
77+
let output_fpath ~via_symlink t tname =
78+
Filename.concat (log_dir ~via_symlink t) (Test_name.file tname)
7279

7380
let active_or_exn = function
7481
| Active t -> t
7582
| Inactive -> failwith "internal error: no log location"
7683

7784
let pp_current_run_dir t ppf =
7885
let t = active_or_exn t in
79-
pp_path ppf (log_dir t)
86+
pp_path ppf (log_dir ~via_symlink:true t)
8087

8188
let pp_log_location t tname ppf =
8289
let t = active_or_exn t in
83-
let path = output_fpath t tname in
90+
let path = output_fpath ~via_symlink:true t tname in
8491
pp_path ppf path
8592

8693
let recover_logs t ~tail tname =
8794
match t with
8895
| Inactive -> None
8996
| Active t -> (
90-
let fpath = output_fpath t tname in
97+
let fpath = output_fpath ~via_symlink:false t tname in
9198
match Platform.file_exists fpath with
9299
| false -> None
93100
| true -> Some (fun ppf -> pp_tail tail fpath ppf))
@@ -96,7 +103,9 @@ struct
96103
match t with
97104
| Inactive -> f x
98105
| Active t ->
99-
let fd = Platform.open_write_only (output_fpath t tname) in
106+
let fd =
107+
Platform.open_write_only (output_fpath ~via_symlink:false t tname)
108+
in
100109
let* () = Promise.return () in
101110
let+ a = Platform.with_redirect fd (fun () -> f x) in
102111
Platform.close fd;

0 commit comments

Comments
 (0)