Tests and concurrency

Tests and concurrency

by Yoan Yvan Hubert Martin -
Number of replies: 7

Hello all, 

I manage to write my code such that each test works individually. However, when I run all the tests together, I face the error "address already in use". I suspect that tests are executed concurrently. Hence, many peers can be initialized with the same address returning this error. 

I don't know how to correct this, do you think it comes from the tests files? Can there be something wrong regarding my concurrency management? 

Thank you for your reply :)

In reply to Yoan Yvan Hubert Martin

Re: Tests and concurrency

by Huan-Cheng Chang -
If you want to run your tests locally, do this:

go test ./... -p 1

This is because some test cases use the same port. Go runs your test suites in parallel by default, depending on how many available CPUs you have in your machine, so when they try to open the same port, the error you saw is thrown.
In reply to Yoan Yvan Hubert Martin

Re: Tests and concurrency

by Cristina Basescu -

Hi Yoan,

Huan-Cheng is right (and thanks to him for previously reporting the issue to us). When running tests locally, please use "-p". When running the tests on gitlab, you shouldn't experience this problem - could you confirm this?

We'll fix the issue for future assignments by using random ports. However, for this assignment we'll keep the test ports as they are.

Cristina

In reply to Cristina Basescu

Re: Tests and concurrency

by Yoan Yvan Hubert Martin -

Thank you both for your quick reply! Running tests using "-p" solves my problem locally. However, I still experience the issue on Gitlab

In reply to Yoan Yvan Hubert Martin

Re: Tests and concurrency

by Aaron Joos Lippeveldts -

I added -p 1 to the .gitlab-ci.yml file in the root of the project, that fixed it for me on GitLab.

In reply to Aaron Joos Lippeveldts

Re: Tests and concurrency

by Cristina Basescu -

That's indeed the way to do it.

Thanks all,

Cristina

In reply to Cristina Basescu

Re: Tests and concurrency

by Elie Daou -

Hello, are the CI machines shared between students? while running the tests on GitLab with -p 1 added I encountered this error which made the tests fail:

> E : cli.go:36 (cli.sendMsg) - Post "http://127.0.0.1:2001/message": dial tcp 127.0.0.1:2001: connect: connection refused

After two retries with the same error the pipeline passed on the third try. Could it be an unavailable port or should I look for a problem elsewhere?
In reply to Elie Daou

Re: Tests and concurrency

by Cristina Basescu -

Hi,

Sharing doesn't cause this problem. The machine is indeed shared, but the environment not: every student's tests run in a docker container.

Have you taken a look at this thread? [1] Might solve your problem.

Cristina

[1] https://moodlearchive.epfl.ch/2020-2021/mod/forum/discuss.php?d=42548