swap: fix race condition in tests#1693
Conversation
ralph-pichler
left a comment
There was a problem hiding this comment.
Seems to work. Not the biggest fan of having yet another function as a global variable but it should be ok for now (the cashing logic needs complete rewriting and sane error handling anyway, maybe we can get rid of this then). Is there a specific reason why WaitFunc is defined on Swap but defaultSubmitChequeAndCash is a global var?
|
@ralph-pichler not sure I get your comment completely, but |
|
@holisticode you're right. Mistook the |
|
I indeed hope that the rewrite of the cashing logic will address this current design in a more profound way |
swap/swap_test.go
Outdated
| testChequeContract = common.HexToAddress("0x4405415b2B8c9F9aA83E151637B8378dD3bcfEDD") | ||
| gasLimit = uint64(8000000) | ||
| testBackend *backends.SimulatedBackend | ||
| errc chan error |
There was a problem hiding this comment.
This channel is just closed, it should be chan struct{}, and probably should be renamed to something like submitDone.
I would also like to see that this channel is not in the global scope if that is even possible. Not crucial.
There was a problem hiding this comment.
I removed it from global, although the design is still not fantastic but is acceptable now in view that the whole async submit and cashing flow will be refactored
* swap: fix race condition in tests
This PR fixes a race condition in tests.
Due to the asynchronous execution of submitting a cheque and cashing it in immediately, if we call that sequence manually in a test, the function will return before the intended operations have terminated (go routine), affecting the nonce for subsequent calls.