csfrancis/gonan — pull request #2 by aybabtme (2014-01-22 00:56:23+00:00)
Title: Reuse goroutines, fix race conditions

* Reuse goroutines instead of spawning new ones at each request.
* Some refactor to follow Go idioms (declarations).
* Create a `gonanClient` type wrapping `http.Client`, to avoid type casts of `gonanRoundTripper`.
* Close channels.
* Fix race condition on WaitGroup and Cancelled.
* Limit the GoogleFlow to use 100 concurrent workers, as OS X doesn't allow 500 connections by default (inconvenient to try out the tool).
* Change test, `Run.Cancel` returns an error on the `errchan` of `ExecuteAsync()`, but doesn't create an error in the NumSuccess/NumError fields. The logic behind that is that a call to `Cancel` is not a connection error, thus shouldn't be counted as one. Unless I missunderstood something.

Other things I've noticed but haven't fixed:
* Error messages in Go usually don't include filename/line number, but a message to give context. They then bubble up the call stack with calls to `fmt.Errorf("happened in this context: %v", err)`, which make the errors traceable.
* The count of requests sent is double the real count (seems to be `gonanRoundTripper`'s fault). See:

```
$ go run examples/gonan-google/main.go
Executed run in 6.639340435s, err=
10000 requests sent (5000 success, 0 errors).
```
I'm not sure if this is because Google returns a 302 and client.Get follows it.