Skip to content

ct: fix -dir and ERL_LIBS for app-provider compiled_suites#7

Open
sebastiw wants to merge 1 commit into
developfrom
fix/ct-test-compiled-suites-app
Open

ct: fix -dir and ERL_LIBS for app-provider compiled_suites#7
sebastiw wants to merge 1 commit into
developfrom
fix/ct-test-compiled-suites-app

Conversation

@sebastiw

Copy link
Copy Markdown
Collaborator

Two regressions in private/ct.bzl::_impl, both surfacing only when an ErlangAppInfo-providing target (e.g. a :test_erlang_app produced by extract_app(test = True)) is passed as compiled_suites rather than the bare erlang_bytecode outputs the ct_suite macro produces.

1. -dir test is bogus when the suite beam is not in test/

8faae61 ("Resurrect CI: ... -dir ebin -> -dir test") fixed the ct_suite macro path (its erlang_bytecode("..._beam_files", dest = "test") puts the suite at test/<suite>.beam) but hardcoded the arg. When compiled_suites is an extract_app target, the suite beam post-e70ed5a lives at <target>/ebin/<suite>.beam — no test/ exists in the runfiles tree. ct_run aborts with

Directory .../test is invalid
Test run failed! Reason: {make_failed, [...]}

Compute -dir from the package-relative dirnames of the _SUITE.beam entries in compiled_suites; fall back to "test" when none are found (defensive — ct_run would error on an empty -dir arg). Drop the now-redundant -pa <dir> for any path already covered by -dir.

2. ERL_LIBS missing the app under test and its prod deps

228b062 originally built ERL_LIBS via
flat_deps(ctx.attr.deps + ctx.attr.compiled_suites). 8faae61 narrowed that to flat_deps(ctx.attr.deps) because compiled_suites under the ct_suite macro are erlang_bytecode outputs and don't provide ErlangAppInfo, so flat_deps's dep[ErlangAppInfo] access fails at analysis.

That's correct for the macro path, but it stripped the transitive app closure that an extract_app(test = True) target contributes. Suites that rely on application:ensure_all_started/1 of the app under test then fail init_per_suite because the app's prod deps are not in ERL_LIBS, e.g.

{badmatch,{error,{some_dep,{"no such file or directory" ...

Re-include only the ErlangAppInfo-providing entries of compiled_suites in the flat_deps call, leaving plain .beam targets alone.

Validation

  • cd test && bazelisk test //... -> 13/13 PASS
  • cd examples/umbrella && bazelisk test //... -> 9/9 PASS
    (covers the ct_suite macro path via umbrella_smoke_SUITE).
  • Reproduced and fixed against a downstream consumer with ct_test
    targets of the form
    ct_test(compiled_suites = [":test_erlang_app"], ...):
    before, every such target failed with the Directory ... is invalid
    error above (or, with Bump golang.org/x/net from 0.17.0 to 0.23.0 in /test #1 alone applied, init_per_suite crashed on
    the missing prod dep); after, they pass.

Two regressions in `private/ct.bzl::_impl`, both surfacing only when an
`ErlangAppInfo`-providing target (e.g. a `:test_erlang_app` produced
by `extract_app(test = True)`) is passed as `compiled_suites` rather
than the bare `erlang_bytecode` outputs the `ct_suite` macro produces.

## 1. `-dir test` is bogus when the suite beam is not in `test/`

8faae61 ("Resurrect CI: ... -dir ebin -> -dir test") fixed the
`ct_suite` macro path (its `erlang_bytecode("..._beam_files", dest =
"test")` puts the suite at `test/<suite>.beam`) but hardcoded the
arg.  When `compiled_suites` is an `extract_app` target, the suite
beam post-e70ed5a lives at `<target>/ebin/<suite>.beam` — no `test/`
exists in the runfiles tree.  `ct_run` aborts with

    Directory .../test is invalid
    Test run failed! Reason: {make_failed, [...]}

Compute `-dir` from the package-relative dirnames of the `_SUITE.beam`
entries in `compiled_suites`; fall back to `"test"` when none are
found (defensive — `ct_run` would error on an empty `-dir` arg).
Drop the now-redundant `-pa <dir>` for any path already covered by
`-dir`.

## 2. ERL_LIBS missing the app under test and its prod deps

228b062 originally built ERL_LIBS via
`flat_deps(ctx.attr.deps + ctx.attr.compiled_suites)`.  8faae61
narrowed that to `flat_deps(ctx.attr.deps)` because `compiled_suites`
under the `ct_suite` macro are `erlang_bytecode` outputs and don't
provide `ErlangAppInfo`, so `flat_deps`'s `dep[ErlangAppInfo]` access
fails at analysis.

That's correct for the macro path, but it stripped the transitive app
closure that an `extract_app(test = True)` target contributes.  Suites
that rely on `application:ensure_all_started/1` of the app under test
then fail `init_per_suite` because the app's prod deps are not in
ERL_LIBS, e.g.

    {badmatch,{error,{some_dep,{"no such file or directory" ...

Re-include only the `ErlangAppInfo`-providing entries of
`compiled_suites` in the `flat_deps` call, leaving plain `.beam`
targets alone.

## Validation

- `cd test && bazelisk test //...`              -> 13/13 PASS
- `cd examples/umbrella && bazelisk test //...` ->  9/9 PASS
  (covers the `ct_suite` macro path via `umbrella_smoke_SUITE`).
- Reproduced and fixed against a downstream consumer with `ct_test`
  targets of the form
  `ct_test(compiled_suites = [":test_erlang_app"], ...)`:
  before, every such target failed with the `Directory ... is invalid`
  error above (or, with #1 alone applied, `init_per_suite` crashed on
  the missing prod dep); after, they pass.
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