Plutonomicon / cardano-transaction-lib

A Purescript library for building smart contract transactions on Cardano
https://plutonomicon.github.io/cardano-transaction-lib/
MIT License
92 stars 50 forks source link

Issues with interrupting Plutip tests with `Ctrl+C` #1580

Open mikekeke opened 8 months ago

mikekeke commented 8 months ago

I'm experiencing the following issue (at least up to the v6.0.0 release) when interrupting Plutip tests: after pressing Ctrl+C I see this error in the terminal

node:internal/fs/utils:350
    throw err;
    ^

Error: ENOENT: no such file or directory, lstat '/tmp/nix-shell.Od5tH5/kupo-db'
    at Object.lstatSync (node:fs:1668:3)
    at __node_internal_ (node:internal/fs/utils:825:8)
    at Object.rmSync (node:fs:1275:13)
    at /home/mike/dev/mlabs/clarity-project/my-ctl-fork/output/Ctl.Internal.Plutip.Spawn/foreign.js:9:39
    at ChildProcess.<anonymous> (/home/mike/dev/mlabs/clarity-project/my-ctl-fork/output/Node.ChildProcess/foreign.js:88:40)
    at ChildProcess.emit (node:events:517:28)
    at ChildProcess._handle.onexit (node:internal/child_process:292:12) {
  errno: -2,
  syscall: 'lstat',
  code: 'ENOENT',
  path: '/tmp/nix-shell.XXX/kupo-db'
}

It seems like this is caused by Kupo having two handlers that attempt to delete test directory: one on SIGINT and one on exit. In the case of pressing Ctrl+C, kupo-db is deleted by the on-SIGINT handler, and then the onexit handler fails to delete the nonexistent directory.

Some other consequences I've noticed besides error in the terminal: sometimes I see that directory of test cluster was not deleted from temp directory.

Although, after fixing this issue in some simplest way (e.g. adding try to directory deletion in onexit handler) I'm facing another issue: after pressing Ctrl+C process detaches instead of exiting and test suite runs till completion. I was testing with suite like this

suite :: TestPlanM (Aff Unit) Unit
suite = do
  test
    "interruption test-1" $ do
    withPlutipContractEnv ctcPlutipConfig testDistribution
      \env wallet -> do
        do
          runContractInEnv env $ withKeyWallet wallet do
            logInfo' "starting delay 10s - press CTRL + C"
            liftAff $ delay (Milliseconds (10000.0 :: Number))
            logInfo' "delay end"
            logInfo' "test end"
  test
    "interruption test -2" $ do
    withPlutipContractEnv ctcPlutipConfig testDistribution
      \env wallet -> do
        do
          runContractInEnv env $ withKeyWallet wallet do
            logInfo' "second test"

and if I press Ctrl+C after "starting delay 10s - press CTRL + C" log message, when delay is over I still see "delay end" and "test end" messages, as well as execution of "interruption test -2"

Renegatto commented 3 months ago

Note, that many cleanups may be performed on the single cleanup handler (since it is not restricted), so you could call cleanup accidentally many times in tests. However this should not be an issue if cleanup errors are catched well. So my opinion is that here are two issues:

First issue can be solved by preventing CTL cleanups from throwing async exceptions. For instance the one you have experienced: #1619