Git Product home page Git Product logo

Comments (4)

adrian-gierakowski avatar adrian-gierakowski commented on May 16, 2024 2

testScript can itself be a service that depends on the service that it testing. The testScript service should only start in CI.

Good idea! Once this PR is merged it will be super easy to run tests within process compose: once test process completes, other processes will be stopped and PC will exit with the code returned by the test process.

from services-flake.

shivaraj-bh avatar shivaraj-bh commented on May 16, 2024 1

Another approach

testScript can itself be a service that depends on the service that it testing. The testScript service should only start in CI.

from services-flake.

srid avatar srid commented on May 16, 2024

Note: this is mostly upstream work Platonic-Systems/process-compose-flake#36

from services-flake.

shivaraj-bh avatar shivaraj-bh commented on May 16, 2024

I have been thinking of different ways to implement this.

I have an idea and that involves having a testScript option for every service (resolves #33).

{
  testScript = lib.mkOption {
    type = types.nullOr (types.functionTo types.package);
    default = null;
    description = ''
      A package that contains a script to test the database.
      The script will be run after the database has been initialized.
    '';
    example = lib.literalExpression
    ''
      package: pkgs.writeShellApplication {
        name = "test-postgres";
        text = "echo 'SELECT version();' | ${package} -h 127.0.0.1";
      };
    '';
  };
}

The option will be used to create a process that will execute the testScript and end with whatever exit code the script returns (courtesy exit_on_end).

{
  "${name}-test" = lib.mkIf (config.testScript != null) {
    command = config.testScript config.package;
    depends_on."${name}".condition = "process_healthy";
    availability.exit_on_end = true;
  };
}

All looks good until we have more than one process that has a testScript, in that case whichever script executes first will be ran and all the other processes are immediately shutdown because exit_on_end waits for no one. I was thinking of a possible way to go around this by having a parent process that will use exit_on_end and this process will depend on all the testScripts. The parent process will have to somehow return the exit code 0 if all the testScripts ran successfully or the non-zero exit code of the first process that fails. I can't think of any way this can be done, any suggestions?

from services-flake.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.