-
Notifications
You must be signed in to change notification settings - Fork 2.3k
truffle test
hangs if no networks
are specified and Ganache is running on port 7545
#1976
Comments
@davidmurdoch Is this still a relevant issue? |
Yes. I just tested with truffle v5.0.18 |
@davidmurdoch I don't seem able to reproduce your specific error. If I fire up Ganache (
If I change the Ganache network id to 4447, I get no errors, the tests pass, and tx's populate in the Ganache dashboard. |
Start up Ganache UI, make sure it is running on port
|
The |
If you don't have Ganache UI running on port 7545 and you run
|
Run Ganache UI on port 7545 then run |
Huh, what OS are you using? |
Ubuntu 18.04 |
Testing on Windows 10 and it returns the The error message |
4447 is the default #1577 is an outstanding PR to change the default |
Even if #1577 is fixed the error message would still be inaccurate in cases where the ganache network id was changed. |
Good point! The default |
I face a similar issue when I download a fresh instance of MetaCoin box. Truffle compile, truffle migrate works (looks like if Ganache is running, it detects Ganache anyway and deploys successfully), but truffle test just hangs. I was unable to understand why test was hanging, then I realized that in truffle-config.js, there was no network specified as by default all lines are commented out. Once I uncommented the "development" section, truffle test succeeded! It would be good if truffle test command could check and warn that there is no network specified. |
Same issue with truffle v5.1.0 |
When Ganache is running on port 7545, somehow the network id is set by Truffle to 4447 yet it somehow knows that Ganache is running at 7545 and the network ids conflict. It would be a good idea to test other ports for these same symptoms. |
If no network options are set when running I think a solution would be to by default choose a different port to lessen the chance that this clash will occur. This will lessen the chance of a clash since common (past and present) port defaults for Ganache are |
I am using Ubuntu 20.X, in my case as well "truffle test" hangs.
|
From a quick look, I believe
truffle/packages/truffle-core/lib/develop.js
Lines 23 to 26 in cbd741b
If the child process can't start ganache then when it rejects (here:
truffle/packages/truffle-core/chain.js
Line 237 in cbd741b
truffle.ready
event (here:truffle/packages/truffle-core/chain.js
Line 249 in cbd741b
Also, if the chain.js process crashes truffle doesn't seem to be listening. Might need to listen to the close event: https://nodejs.org/api/child_process.html#child_process_event_close
I don't seen any harm in using a different port for truffle's internal ganache server instance, but I don't have much experience with using truffle myself. For reliability you could (should?) try to start the ganache-core server on a random port, if it fails due to the port already being bound, try again on another random port, and maybe a few more tries before failing.
Alternatively, you could do what
truffle migrate
does and just (try to) use the already bound 7545 port.To get a big speed boost you could experiement with running ganache-core as a provider (Ganache.provider(options) instead of
Ganache.server(options)
.Let me know if you have ganache-related questions!
The text was updated successfully, but these errors were encountered: