Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be able to allocate a formatter for stdout/stderr #399

Merged
merged 4 commits into from
May 31, 2024

Conversation

dinosaure
Copy link
Member

This pull-request, as a draft, wants to solve the issue #398 and solve a data-race on formatters used by Alcotest where they are also used by something else like Logs in a parallel task. Currently, this PR is a draft because I'm not really sure about the design. Three points are importants:

  1. to be coherent into our usage of stdout/stderr and what is required by alcotest-engine (eg. Platform), the user is only able to create these values via Alcotest.Global.make_{stdout,stderr} to ensure that these values use Stdlib.std{out,err}. Indeed, we don't want to let the user to create a Format.formatter which does not uses Stdlib.std{out,err} (something like Format.str_formatter for instance).
  2. The library was tested with TSan and httpcats which launches several tasks in parallel and uses Logs in these parallel tasks with Format.{std,err}_formatter
  3. A controversial change was made about pp_summary where the newline does not appear anymore but I don't really understand why. Otherwise, the ouput seems the same as before.

using OCaml's formatter - fix some data-race when some parallel tasks
use the same formatter.

This commit tries to solve an issue about OCaml 5 and parallelism.
Alcotest uses OCaml's formatter which can be used by some libraries such
as Logs. In this situation and if Logs is used into a parallel task, a
data-race exists about the internal queue used by formatters.

This commit allows the user to allocate its own formatter for
stdout/stderr and give them to Alcotest.
src/alcotest-engine/pp.ml Outdated Show resolved Hide resolved
@dinosaure dinosaure marked this pull request as ready for review October 15, 2023 09:15
@dinosaure
Copy link
Member Author

It will be really pleasant if someone can look on this PR and merge it. Tests are passing and a real issue exists in the actual state of Alcotest.

Copy link
Collaborator

@MisterDA MisterDA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@dinosaure dinosaure merged commit 1cc743c into mirage:main May 31, 2024
11 of 12 checks passed
@dinosaure dinosaure deleted the safe-formatter branch May 31, 2024 09:30
samoht added a commit to samoht/opam-repository that referenced this pull request Jul 25, 2024
CHANGES:

- Add `match_raises`, a generalized version of `check_raises`
  (mirage/alcotest#88, mirage/alcotest#386, @JoanThibault)

- Update JaneStreet core and async to v0.16 (mirage/alcotest#390 @tmcgilchrist)

- Fix division by zero when size of the terminal is incorrectly
  reported as zero. (fix mirage/alcotest#356, mirage/alcotest#381, @MisterDA)

- Enable terminal size reporting on macOS and Windows. Also report the
  terminal size even when the test is run buffered by Dune.
  (mirage/alcotest#381, mirage/alcotest#396, @MisterDA)

- Allow overriding the number of columns with `ALCOTEST_COLUMNS` env
  var. (mirage/alcotest#322, mirage/alcotest#381, @MisterDA)

- Be able to allocate and use user's formatters for stdout/stderr
  (mirage/alcotest#399, @dinosaure)

- Stop detecting ocamlci specifically, since there's nothing specific
  about it. Simply use the `CI` env var to detect CIs. Improve CI
  detection.
  (mirage/alcotest#397, @MisterDA)
Halbaroth pushed a commit to Halbaroth/opam-repository that referenced this pull request Jul 26, 2024
CHANGES:

- Add `match_raises`, a generalized version of `check_raises`
  (mirage/alcotest#88, mirage/alcotest#386, @JoanThibault)

- Update JaneStreet core and async to v0.16 (mirage/alcotest#390 @tmcgilchrist)

- Fix division by zero when size of the terminal is incorrectly
  reported as zero. (fix mirage/alcotest#356, mirage/alcotest#381, @MisterDA)

- Enable terminal size reporting on macOS and Windows. Also report the
  terminal size even when the test is run buffered by Dune.
  (mirage/alcotest#381, mirage/alcotest#396, @MisterDA)

- Allow overriding the number of columns with `ALCOTEST_COLUMNS` env
  var. (mirage/alcotest#322, mirage/alcotest#381, @MisterDA)

- Be able to allocate and use user's formatters for stdout/stderr
  (mirage/alcotest#399, @dinosaure)

- Stop detecting ocamlci specifically, since there's nothing specific
  about it. Simply use the `CI` env var to detect CIs. Improve CI
  detection.
  (mirage/alcotest#397, @MisterDA)
avsm pushed a commit to avsm/opam-repository that referenced this pull request Sep 5, 2024
CHANGES:

- Add `match_raises`, a generalized version of `check_raises`
  (mirage/alcotest#88, mirage/alcotest#386, @JoanThibault)

- Update JaneStreet core and async to v0.16 (mirage/alcotest#390 @tmcgilchrist)

- Fix division by zero when size of the terminal is incorrectly
  reported as zero. (fix mirage/alcotest#356, mirage/alcotest#381, @MisterDA)

- Enable terminal size reporting on macOS and Windows. Also report the
  terminal size even when the test is run buffered by Dune.
  (mirage/alcotest#381, mirage/alcotest#396, @MisterDA)

- Allow overriding the number of columns with `ALCOTEST_COLUMNS` env
  var. (mirage/alcotest#322, mirage/alcotest#381, @MisterDA)

- Be able to allocate and use user's formatters for stdout/stderr
  (mirage/alcotest#399, @dinosaure)

- Stop detecting ocamlci specifically, since there's nothing specific
  about it. Simply use the `CI` env var to detect CIs. Improve CI
  detection.
  (mirage/alcotest#397, @MisterDA)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants