4

When I try to run 'anchor test' (on Ubuntu 20.04.1) following this tutorial https://dev.to/edge-and-node/the-complete-guide-to-full-stack-solana-development-with-react-anchor-rust-and-phantom-3291

I get this error on a new project:

Error: Your configured rpc port: 8899 is already in use

I can't find a solution online - I found this but it doesn't explain what went wrong and their solution also doesn't help: https://forums.solana.com/t/unable-test-the-solana-program-your-configured-rpc-port-8899-is-already-in-use/7745

https://github.com/solana-labs/solana/issues/24929

I've tried rebooting Ubuntu and it doesn't help.

Why is this happening and how can I fix it?

UPDATE This only seems to happen if solana-test-validator is running. Why would that be?

2 Answers 2

4

This happens only when you have a test validator running because anchor test runs its own validator as well. When it tries it sees that your validator is already listening on port 8899 and crashes. You don't need to run your own validator with anchor test but if you want to you can run anchor test --skip-local-validator.

1
  • Thanks. I did try the --skip-local-validator thing, as recommended by one of the above links, but it errors 'Error: failed to send transaction: Transaction simulation failed: Attempt to load a program that does not exist' Bottom line though is don't have a local validator running when running anchor test?
    – niico
    Sep 17, 2022 at 0:22
2

I recently ran into this issue and I will share how I fixed it.

Apparently (yet to see this documented) there are two commands that can be used to run tests in Anchor. anchor test or anchor run test.

When anchor test is used, Anchor will spin up its own instance of the solana test validator, before running the test script configured in the [scripts] section of Anchor.toml. When you use this method, if you have already running validator, then it will fail with the error:

Error: Your configured rpc port: 8899 is already in use

If you use anchor run test on the other hand, Anchor does not start it's own instance of solana test validator but just runs the test scripts as defined in the [scripts] section of Anchor.toml.

So there are two ways to go about it. If you want to run the tests against your own instance of the solana test validator that you start locally, then use anchor run test to run the tests.

If you want Anchor to take care of spinning an instance of a test validator to be used in testing, then make sure you are not running an instance of the solana test validator and then run your tests with anchor test

You can also run anchor test without having Anchor start its own instance of the solana test validator by passing in the --skip-local-validator flag. That is anchor test --skip-local-validator will only run the tests but won't start a local solana validator.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.