Skip to content
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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

jdietrich-tc
Copy link
Contributor

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.

@@ -43,17 +45,21 @@ func TestReadFile(t *testing.T) {

func TestHTTPContent(t *testing.T) {
st := Stream{}
wg := &sync.WaitGroup{}
Copy link
Owner

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!

Copy link
Contributor Author

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.

Copy link
Owner

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.

Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants