I'm working on a command line tool that fetches data from an oauth1 webserivce. The requests can be highly variable in duration. After getting my solution working with sequential requests, I'm now attempting to add some concurrency to reduce the execution time.
I've modified my code so that the client.Get requests are happening in a go routine where the client is supplied via a pointer argument (all go routines are using the same client). After a few runs against the web service it started giving me errors about the nonce being reused.
In my proxy I could see that early requests were supplying single digit nonce in the authorization header.
I've written this unit test that demonstrates what I'm experiencing.
func TestNonceInGoRoutine(t *testing.T) {
nonces := make(chan string)
var getNonce = func(nonces chan<- string) {
nonces <- nonce()
}
count := 5
for i := 0; i < count; i++ {
go getNonce(nonces)
}
for i := 0; i < count; i++ {
select {
case n := <-nonces:
fmt.Printf("nonce is %s, expected something longer\n", n)
if len(n) < 8 {
t.Fatalf("nonce is %s, expected something longer", n)
}
}
}
}
I'm really new to GO so I may have the wrong idea.
I'm using GO version 1.7.3 on osx.