-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use local web service for test #172
base: master
Are you sure you want to change the base?
Use local web service for test #172
Conversation
a68e4b0
to
ca32ae0
Compare
@@ -43,17 +45,21 @@ func TestReadFile(t *testing.T) { | |||
|
|||
func TestHTTPContent(t *testing.T) { | |||
st := Stream{} | |||
wg := &sync.WaitGroup{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I'm struggeling to see why the WaitGroup is used. Could you elaborate a bit for me?
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It pauses the test until the http server is up and running. It communicates such when it calls the wait groups done function same then it passes back a handle to the server so that the test can shut the server done.
Without it, there is a race condition between starting the server and attempting to use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I don’t see any wg.Wait() that makes the test wait as you are describing. That's why a bit lost.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, I'm not sure exactly how it works. I'm new to go (mmock is the first go code I've ever worked with) I found that I couldn't shut down the server once started, this hanging the tests. I found this, and it works.
https://stackoverflow.com/questions/39320025/how-to-stop-http-listenandserve
Instead of relying on connectivity of
https://golang.org/
for testing http streaming, use a local web server, and call it. This makes the tests quicker and more reliable.