gomaasapi: use a giant honking lock around all API calls #3

Merged
merged 1 commit into from Jan 19, 2016
Jump to file or symbol
Failed to load files and symbols.
+21 −7
Split
View
@@ -7,10 +7,11 @@ import (
"bytes"
"fmt"
"io/ioutil"
- . "gopkg.in/check.v1"
"net/http"
"net/url"
"strings"
+
+ . "gopkg.in/check.v1"
)
type ClientSuite struct{}
@@ -11,8 +11,9 @@ package main
import (
"bytes"
"fmt"
- "github.com/juju/gomaasapi"
"net/url"
+
+ "github.com/juju/gomaasapi"
)
var apiKey string
View
@@ -4,8 +4,9 @@
package gomaasapi
import (
- . "gopkg.in/check.v1"
"testing"
+
+ . "gopkg.in/check.v1"
)
func Test(t *testing.T) {
View
@@ -6,6 +6,7 @@ package gomaasapi
import (
"encoding/json"
"fmt"
+
. "gopkg.in/check.v1"
)
View
@@ -4,8 +4,9 @@
package gomaasapi
import (
- . "gopkg.in/check.v1"
"net/url"
+
+ . "gopkg.in/check.v1"
)
type MAASSuite struct{}
View
@@ -6,9 +6,10 @@ package gomaasapi
import (
"encoding/json"
"fmt"
- . "gopkg.in/check.v1"
"math/rand"
"net/url"
+
+ . "gopkg.in/check.v1"
)
type MAASObjectSuite struct{}
View
@@ -19,6 +19,7 @@ import (
"sort"
"strconv"
"strings"
+ "sync"
"text/template"
"time"
@@ -595,7 +596,14 @@ func NewTestServer(version string) *TestServer {
vlansHandler(server, w, r)
})
- newServer := httptest.NewServer(serveMux)
+ var mu sync.Mutex
+ singleFile := func(w http.ResponseWriter, req *http.Request) {
+ mu.Lock()
+ defer mu.Unlock()
+ serveMux.ServeHTTP(w, req)
+ }
+
+ newServer := httptest.NewServer(http.HandlerFunc(singleFile))
client, err := NewAnonymousClient(newServer.URL, "1.0")
checkError(err)
server.Server = newServer
View
@@ -18,8 +18,8 @@ import (
"strconv"
"strings"
- "gopkg.in/mgo.v2/bson"
. "gopkg.in/check.v1"
+ "gopkg.in/mgo.v2/bson"
)
type TestServerSuite struct {