Browse Source

fix(internal_version_test.go) protect the checkedVersion by a lock

Xiang Li 11 years ago
parent
commit
fc84da29e8
1 changed files with 8 additions and 0 deletions
  1. 8 0
      tests/functional/internal_version_test.go

+ 8 - 0
tests/functional/internal_version_test.go

@@ -6,17 +6,23 @@ import (
 	"net/http/httptest"
 	"net/http/httptest"
 	"net/url"
 	"net/url"
 	"os"
 	"os"
+	"sync"
 	"testing"
 	"testing"
 	"time"
 	"time"
 )
 )
 
 
 // Ensure that etcd does not come up if the internal raft versions do not match.
 // Ensure that etcd does not come up if the internal raft versions do not match.
 func TestInternalVersion(t *testing.T) {
 func TestInternalVersion(t *testing.T) {
+	var mu sync.Mutex
+
 	checkedVersion := false
 	checkedVersion := false
 	testMux := http.NewServeMux()
 	testMux := http.NewServeMux()
 
 
 	testMux.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
 	testMux.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
 		fmt.Fprintln(w, "This is not a version number")
 		fmt.Fprintln(w, "This is not a version number")
+		mu.Lock()
+		defer mu.Unlock()
+
 		checkedVersion = true
 		checkedVersion = true
 	})
 	})
 
 
@@ -48,6 +54,8 @@ func TestInternalVersion(t *testing.T) {
 		return
 		return
 	}
 	}
 
 
+	mu.Lock()
+	defer mu.Unlock()
 	if checkedVersion == false {
 	if checkedVersion == false {
 		t.Fatal("etcd did not check the version")
 		t.Fatal("etcd did not check the version")
 		return
 		return