`truffle test` hangs if no `networks` are specified and Ganache is running on port `7545`
See original GitHub issueFrom a quick look, I believe https://github.com/trufflesuite/truffle/blob/cbd741b40696d6f7f6053ae007e1fdfb22483237/packages/truffle-core/lib/develop.js#L23-L26 is part of the issue.
If the child process can’t start ganache then when it rejects (here: https://github.com/trufflesuite/truffle/blob/cbd741b40696d6f7f6053ae007e1fdfb22483237/packages/truffle-core/chain.js#L237) truffle never gets notified of the truffle.ready
event (here: https://github.com/trufflesuite/truffle/blob/cbd741b40696d6f7f6053ae007e1fdfb22483237/packages/truffle-core/chain.js#L249)
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!
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:18 (15 by maintainers)
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.
I am using Ubuntu 20.X, in my case as well “truffle test” hangs. My Resolution: