Skip to content

Conversation

@somniumism
Copy link
Contributor

Problem

Some e2e tests are emitting UnhandledPromiseRejectionWarning. When we run the tests, we can see the following warning:

ChangeParams
    ✓ change (38ms)
(node:13789) UnhandledPromiseRejectionWarning: Error: CodeChain(3) process state is invalid: {
    "state": "stopping"
}
    at CodeChain.get testFramework [as testFramework] (/home/spkim2/foundry/test/src/helper/spawn.ts:100:19)
    at CodeChain.createPayTx (/home/spkim2/foundry/test/src/helper/spawn.ts:547:21)
    at CodeChain.sendPayTx (/home/spkim2/foundry/test/src/helper/spawn.ts:572:25)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:13789) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:13789) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Cause

This warning message has occurred since Remove all sdk functtions from e2e tests was merged. I suspect a small mistake was made in this work of modifying the test code. Fundamentally, the reason for UnhandledPromiseRejectionWarning occurring is related to the process state below.

(node:13789) UnhandledPromiseRejectionWarning: Error: CodeChain(3) process state is invalid: {
    "state": "stopping"
}

In this test, the process state of the node must be running state. Here the node is the object of class CodeChain. If the process state is stopping or others, Error: CodeChain(3) process state is invalid: occurs. Some logic was misimplemented, so I assumed the state has a stopping state.

I found the problem part, which is as follows:

        try {
            await expect(node.sendPayTx({ fee: 10 }));
        } catch (e) {
            expect(e.toString()).is.include(
                ERROR.ACTION_DATA_HANDLER_NOT_FOUND
            );
        }

In normal case, sendPayTx() should be executed and createPayTx() in sendPayTx() sholud be executed too. In this case, however, sendPayTx() does not work because it is wrapped by expect(). Then, another code outside the try block is executed without sendPayTx() and createPayTx() running. Interestingly, the test ends with a message that the test is completed. After the test, sendPayTx() and createPayTx() is run and the node with the stopping state fails in the following process on createPayTx():

    public get testFramework(): SDK {
        if (this.process.state === "running") {
            return this._testFramework;
        } else {
            throw new ProcessStateError(this.id, this.process);
        }
    }

Since the node is not running state, an error occurs with UnhandledPromiseRejectionWarning during this process.


Solution

If the problem is modified as follows, no further errors will occur.

        try {
            await node.sendPayTx({ fee: 10 });
            expect.fail();
        } catch (e) {
            expect(e.toString()).is.include(
                ERROR.ACTION_DATA_HANDLER_NOT_FOUND
            );
        }

resolved #276

@somniumism somniumism requested a review from HoOngEe March 20, 2020 05:04
@somniumism
Copy link
Contributor Author

somniumism commented Mar 20, 2020

@HoOngEe I tried to check e2e tests to find other UnhandledRejectionWarning, but I couldn't find it. When I ran yarn start-short --unhandled-rejections=strict on upstream/master branch, The following failures can be found:

    1) "after each" hook
(node:25441) UnhandledPromiseRejectionWarning: Error: CodeChain(3) process state is invalid: {
    "state": "stopping"
}
    at CodeChain.get testFramework [as testFramework] (src/helper/spawn.ts:99:19)
    at CodeChain.createPayTx (src/helper/spawn.ts:547:21)
    at CodeChain.sendPayTx (src/helper/spawn.ts:572:25)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:25441) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)

  customAction
    2) "before each" hook for "cannot change the network id"
    3) "after each" hook for "cannot change the network id"
.
.
.
        4) "after all" hook
        ipc
(node:25441) UnhandledPromiseRejectionWarning: TypeError: Cannot set property 'state' of undefined
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:25441) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
        Sealing test
          5) stopSealing then startSealing
Keep log file: /Users/somniumism/Project/PR/foundry/test/src/helper/../../../test/log/2020_03_20T06_29_40_874Z.6.log
          ✓ multiple connections at the same time in the random order
          6) "after each" hook for "multiple connections at the same time in the random order"
.
.
.
  1) ChangeParams
       "after each" hook for "cannot change the network id":
     Uncaught Error: CodeChain(3) process state is invalid: {
    "state": "stopping"
}
      at CodeChain.get testFramework [as testFramework] (src/helper/spawn.ts:99:19)
      at CodeChain.createPayTx (src/helper/spawn.ts:547:21)
      at CodeChain.sendPayTx (src/helper/spawn.ts:572:25)
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

  2) ChangeParams
       "before each" hook for "cannot change the network id":
     TypeError: Cannot read property 'call' of undefined
      at processImmediate (internal/timers.js:456:21)

  3) ChangeParams
       "after each" hook for "cannot change the network id":
     TypeError: Cannot read property 'call' of undefined
      at processImmediate (internal/timers.js:456:21)

  4) engine
       "after all" hook:
     Uncaught TypeError: Cannot set property 'state' of undefined
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

  5) Sealing test
       stopSealing then startSealing:
     Error: CodeChain(7) process state is invalid: {
    "state": "initializing"
}
      at CodeChain.get rpc [as rpc] (src/helper/spawn.ts:106:19)
      at Context.<anonymous> (src/e2e/mempool.test.ts:32:20)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

  6) ipc
       "after each" hook for "multiple connections at the same time in the random order":
     Error: CodeChain(8) process state is invalid: {
    "state": "initializing"
}
      at /Users/somniumism/Project/PR/foundry/test/src/helper/spawn.ts:368:31
      at new Promise (<anonymous>)
      at CodeChain.clean (src/helper/spawn.ts:364:16)
      at Context.<anonymous> (src/e2e/ipc.test.ts:65:20)
      at processImmediate (internal/timers.js:456:21)

However, when I ran ran yarn start-short --unhandled-rejections=strict on THIS PR, I couldn't find any test failure. I still don't understand why the tests don't fail. I think we need another way to find UnhandledRejectionWarning. Do you know anyway?

@HoOngEe HoOngEe requested a review from majecty March 20, 2020 06:43
Copy link
Contributor

@majecty majecty left a comment

Choose a reason for hiding this comment

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

Your PR fixes the UnhandledRejectionWarning error well.
I found that the expect function to check the error message is not working.
I'll create another issue for it.

@somniumism somniumism merged commit bb231c5 into CodeChain-io:master Mar 23, 2020
@somniumism somniumism deleted the modify.test branch March 25, 2020 09:04
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.

Resolve UnhandledRejectionWarning in e2e tests.

3 participants