Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Internal improvement: refactor connectOrStart #4671

Merged
merged 9 commits into from
May 2, 2022
Merged

Conversation

cds-amal
Copy link
Member

@cds-amal cds-amal commented Jan 28, 2022

This PR

  • updates the use of the Ganache's server.close() method, which uses a promise instead of node's callback idiom. We should tear down Ganache properly.
  • cleans up the logic for connectOrStart
  • adds 2 tests to verify connectOfStart try/catch logic path.

Copy link
Contributor

@haltman-at haltman-at left a comment

Choose a reason for hiding this comment

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

Seems basically good to me, confused about something in .eslintrc.json though.

packages/environment/.eslintrc.json Outdated Show resolved Hide resolved
packages/environment/develop.js Show resolved Hide resolved
@cds-amal
Copy link
Member Author

cds-amal commented Jan 29, 2022

This PR continues to be dogged by some race condition(s) that prevents CI from logging completed steps. What a PITA.

Cancelling the job forces a flush, it seems.

@truffle/environment: connectOrStart test network
@truffle/environment: ✓ starts Ganache when no Ganache instance is running (1561ms)
@truffle/environment: ✓ connects to an established Ganache instance (1056ms)

Ah, this PR's tests pass, but did it break another test? 🤔

@truffle/environment: Environment develop
@truffle/environment: - Preparing to download box
@truffle/environment: ✔ Preparing to download box
@truffle/environment: - Downloading
@truffle/environment: ✖ Downloading
@truffle/environment: Unbox failed!
@truffle/environment: ✖ Downloading
@truffle/environment: Unbox failed!
@truffle/environment: 1) "before each" hook: Create a sandbox for "Environment.develop overwrites the network_id of the network"
@truffle/environment: 2) "after each" hook: Restore Environment detect for "Environment.develop overwrites the network_id of the network"
@truffle/environment: 2 passing (4s)
@truffle/environment: 2 failing
@truffle/environment: 1) Environment develop
@truffle/environment: "before each" hook: Create a sandbox for "Environment.develop overwrites the network_id of the network":
@truffle/environment: Error: Error connecting to https://raw.githubusercontent.com/trufflesuite/truffle-init-default/master/truffle-box.json. Please check your internet connection and try again.
@truffle/environment: Request failed with status code 500
@truffle/environment: at createError (/home/runner/work/truffle/truffle/node_modules/axios/lib/core/createError.js:16:15)
@truffle/environment: at settle (/home/runner/work/truffle/truffle/node_modules/axios/lib/core/settle.js:17:12)
@truffle/environment: at IncomingMessage.handleStreamEnd (/home/runner/work/truffle/truffle/node_modules/axios/lib/adapters/http.js:269:11)
@truffle/environment: at endReadableNT (_stream_readable.js:1241:12)
@truffle/environment: at processTicksAndRejections (internal/process/task_queues.js:84:21)
@truffle/environment: 2) Environment develop
@truffle/environment: "after each" hook: Restore Environment detect for "Environment.develop overwrites the network_id of the network":
@truffle/environment: TypeError: Environment.detect.restore is not a function
@truffle/environment: at Context. (test/develop.js:36:24)
@truffle/environment: at processImmediate (internal/timers.js:461:21)
Error: The operation was canceled.

@haltman-at
Copy link
Contributor

So, wait, is this working now, or was that just luck?

@cds-amal
Copy link
Member Author

cds-amal commented Feb 1, 2022

Hard to tell @haltman-at. I'm going to wait on the fix to Ganache-2185 as it seems to be relevant during my investigation.

@cds-amal
Copy link
Member Author

cds-amal commented Feb 1, 2022

Yep, definitely lucky the last time. I re-ran CI and it failed unable to shut down Ganache, killing the test-runner that needed to be manually cancelled.

@truffle/environment: ✔ Setting up box
@truffle/environment:     ✓ Environment.develop overwrites the network_id of the network
@truffle/environment:   2 passing (3s)
@truffle/environment:   1 failing
@truffle/environment:   1) connectOrStart test network
@truffle/environment:        connects to an established Ganache instance:
@truffle/environment:      Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/home/runner/work/truffle/truffle/packages/environment/test/connectOrStartTest.js)
@truffle/environment:       at listOnTimeout (internal/timers.js:554:17)
@truffle/environment:       at processTimers (internal/timers.js:497:7)
Error: The operation was canceled.

@haltman-at
Copy link
Contributor

Oh hey a quick note, the .eslintrc.json changes are no longer necessary as of #4698; I'd suggest rebasing if you haven't and removing that change because it's redundant.

@cds-amal
Copy link
Member Author

Oh hey a quick note, the .eslintrc.json changes are no longer necessary as of #4698; I'd suggest rebasing if you haven't and removing that change because it's redundant.

Good catch! rebasing.

Copy link
Contributor

@haltman-at haltman-at left a comment

Choose a reason for hiding this comment

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

Seems mostly good to me (as best I can understand anyway); just two questions about the tests.

packages/environment/test/develop.js Show resolved Hide resolved
});

it("Environment.develop overwrites the network_id of the network", async function() {
it("Environment.develop overwrites the network_id of the network", async function () {
sinon.stub(Environment, "detect");
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused why this is being stubbed... what is this for?

Copy link
Member Author

Choose a reason for hiding this comment

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

Environment.develop() invokes Environment.detect() as its final step, which isn't needed to validate the test's assertion. I'll add a clarifying comment and leave potential refactoring for followup work.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, huh, OK. Odd use and I'd suggest getting rid of it, but I guess it's OK to put that off?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is one of those things that touches TruffleConfig's side-effect behavior. There are a bunch of methods in Environment that modify TruffleConfig :/ . A code smell to be addressed later.

Test to validate code path to connect to an established Ganache
server, or no Ganache server.
  - remove catch
  - add messages to assertions
set  instead of invoking , which forces the process to exit as quickly as possible even if there are still asynchronous operations pending that have not yet completed fully, including I/O operations to process.stdout and process.stderr.
Copy link
Contributor

@eggplantzzz eggplantzzz left a comment

Choose a reason for hiding this comment

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

lookin good

Copy link
Contributor

@haltman-at haltman-at left a comment

Choose a reason for hiding this comment

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

OK, looks good to me!

@cds-amal cds-amal merged commit 446efc6 into develop May 2, 2022
@cds-amal cds-amal deleted the connect-or-start branch May 2, 2022 23:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants