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

[backport 2.3] Allow testing with different daemons #5650

Draft
wants to merge 14 commits into
base: 2.3-maintenance
Choose a base branch
from

Commits on Oct 31, 2023

  1. Actually test nix-env with a remote store

    The `remote-store` test loads the `user-env` one to test nix-env when
    using the daemon, but actually does it incorrectly because every test
    starts (in `common.sh`) by resetting the value of `NIX_REMOTE`, meaning
    that the `user-env` test will never use the daemon.
    
    Fix this by setting `NIX_REMOTE_` before sourcing `user-env.sh` in the
    `remote-store` test, so that `NIX_REMOTE` is correctly set inside the
    test
    
    (cherry picked from commit f6ac888)
    thufschmitt authored and Ericson2314 committed Oct 31, 2023
    Configuration menu
    Copy the full SHA
    7ec64b5 View commit details
    Browse the repository at this point in the history
  2. Add a test ensuring compatibility with an old daemon

    This requires adding `nix` to its own closure which is a bit unfortunate,
    but as it is optional (the test will be disabled if `OUTER_NIX` is unset) it
    shouldn't be too much of an issue.
    
    (Ideally this should go in another derivation so that we can build Nix and run
    the test independently, but as the tests are running in the same derivation
    as the build it's a bit complicated to do so).
    
    (cherry picked from commit 5716345)
    thufschmitt authored and Ericson2314 committed Oct 31, 2023
    Configuration menu
    Copy the full SHA
    22482a0 View commit details
    Browse the repository at this point in the history
  3. Make the tests (optionnally) run in another derivation

    That way we can run them without rebuilding Nix
    
    (cherry picked from commit a0866c8)
    thufschmitt authored and Ericson2314 committed Oct 31, 2023
    Configuration menu
    Copy the full SHA
    4ffbede View commit details
    Browse the repository at this point in the history
  4. Allow running all the tests with the daemon

    When `NIX_DAEMON_PACKAGE` is set, make all the tests use the Nix daemon.
    That way we can test every piece of Nix functionality both with and
    without the daemon.
    
    Tests for which using the daemon isn’t possible or doesn’t make sens can
    selectively be disabled with `needLocalStore`
    
    (cherry picked from commit addacfc)
    thufschmitt authored and Ericson2314 committed Oct 31, 2023
    Configuration menu
    Copy the full SHA
    ab862b7 View commit details
    Browse the repository at this point in the history
  5. Remove the right socket before starting the daemon

    For some reason, an old socket occasionally stays here on OSX, causing
    the subsequent tests to fail
    
    (cherry picked from commit c2c0dba)
    thufschmitt authored and Ericson2314 committed Oct 31, 2023
    Configuration menu
    Copy the full SHA
    cf67f7a View commit details
    Browse the repository at this point in the history
  6. mk/tests.mk: document 'installcheck' in 'make help'

    (cherry picked from commit 1e6faa7)
    trofi authored and Ericson2314 committed Oct 31, 2023
    Configuration menu
    Copy the full SHA
    366d01c View commit details
    Browse the repository at this point in the history
  7. Fix the isDaemonNewer check

    - Don’t hardcode the “newer” version
    - Remove an ill-placed `return`
    
    (cherry picked from commit 3a2fc9c)
    thufschmitt authored and Ericson2314 committed Oct 31, 2023
    Configuration menu
    Copy the full SHA
    a495667 View commit details
    Browse the repository at this point in the history
  8. Make the post-build-hook use the daemon Nix package

    Having the `post-build-hook` use `nix` from the client package can lead
    to a deadlock in case there’s a db migration to do between both, as a
    `nix` command running inside the hook will run as root (and as such will
    bypass the daemon), so might trigger a db migration, which will get
    stuck trying to get a global lock on the DB (as the daemon that ran the
    hook already has a lock on it).
    
    (cherry picked from commit 93eadd5)
    thufschmitt authored and Ericson2314 committed Oct 31, 2023
    Configuration menu
    Copy the full SHA
    e693190 View commit details
    Browse the repository at this point in the history
  9. Fix testing the other daemon

    The eventual PATH entry needs the `.../bin` or we will not use the right
    daemon.
    
    (cherry picked from commit 06fb6ae)
    Ericson2314 committed Oct 31, 2023
    Configuration menu
    Copy the full SHA
    cee4cb6 View commit details
    Browse the repository at this point in the history
  10. Flip condition on daemon version for structured attrs

    We want the old behavior, since this is Nix 2.3.
    Ericson2314 committed Oct 31, 2023
    Configuration menu
    Copy the full SHA
    bc28776 View commit details
    Browse the repository at this point in the history
  11. tests: Add command source locations to test log

    (cherry picked from commit 9813e54)
    roberth authored and Ericson2314 committed Oct 31, 2023
    Configuration menu
    Copy the full SHA
    ddb78e1 View commit details
    Browse the repository at this point in the history
  12. Tighten up the exportReferencesGraph tests

    Add an `$` at the end of the `grep` regex. Without it, `checkRef foo`
    would always imply `checkRef foo.drv`. We want to tell these situations
    apart to more precisely test what is going on.
    
    (cherry picked from commit f587598)
    aciceri authored and Ericson2314 committed Oct 31, 2023
    Configuration menu
    Copy the full SHA
    4c1441a View commit details
    Browse the repository at this point in the history
  13. Make init.sh safe to run twice

    (cherry picked from commit 5dbbf23)
    Ericson2314 committed Oct 31, 2023
    Configuration menu
    Copy the full SHA
    0fe5dcb View commit details
    Browse the repository at this point in the history
  14. Harden tests' bash

    Use `set -u` and `set -o pipefail` to catch accidental mistakes and
    failures more strongly.
    
     - `set -u` catches the use of undefined variables
     - `set -o pipefail` catches failures (like `set -e`) earlier in the
       pipeline.
    
    This makes the tests a bit more robust. It is nice to read code not
    worrying about these spurious success paths (via uncaught) errors
    undermining the tests. Indeed, I caught some bugs doing this.
    
    There are a few tests where we run a command that should fail, and then
    search its output to make sure the failure message is one that we
    expect. Before, since the `grep` was the last command in the pipeline
    the exit code of those failing programs was silently ignored. Now with
    `set -o pipefail` it won't be, and we have to do something so the
    expected failure doesn't accidentally fail the test.
    
    To do that we use `expect` and a new `expectStderr` to check for the
    exact failing exit code. See the comments on each for why.
    
    `grep -q` is replaced with `grepQuiet`, see the comments on that
    function for why.
    
    `grep -v` when we just want the exit code is replaced with `grepInverse,
    see the comments on that function for why.
    
    `grep -q -v` together is, surprise surprise, replaced with
    `grepQuietInverse`, which is both combined.
    
    (cherry picked from commit c118361)
    Ericson2314 committed Oct 31, 2023
    Configuration menu
    Copy the full SHA
    0435ae9 View commit details
    Browse the repository at this point in the history