Answer the question
In order to leave comments, you need to log in
How to organize interruption of infinite loops in tests?
I inherited a project written on GO (comet server) and now the task is to cover everything with integration tests.
Comet processes messages from channels (go channels) in an infinite loop, then processes these messages.
In general, how to succinctly organize the interruption of such a cycle in tests after all messages have been processed?
I have only one thought - this is the addition of a new channel, which will be responsible for interrupting the loop, but something like that ...
Answer the question
In order to leave comments, you need to log in
Close the channel in the test, and the function reading in the message loop should terminate gracefully.
Example:
data, ok := <-channel
if !ok {
return
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question