mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
feat add snapCount parameter
This commit is contained in:
46
tests/functional/version_check_test.go
Normal file
46
tests/functional/version_check_test.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Ensure that a node can reply to a version check appropriately.
|
||||
func TestVersionCheck(t *testing.T) {
|
||||
procAttr := new(os.ProcAttr)
|
||||
procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
|
||||
args := []string{"etcd", "-n=node1", "-f", "-d=/tmp/version_check"}
|
||||
|
||||
process, err := os.StartProcess(EtcdBinPath, args, procAttr)
|
||||
if err != nil {
|
||||
t.Fatal("start process failed:" + err.Error())
|
||||
return
|
||||
}
|
||||
defer process.Kill()
|
||||
|
||||
time.Sleep(time.Second)
|
||||
|
||||
// Check a version too small.
|
||||
resp, _ := http.Get("http://localhost:7001/version/1/check")
|
||||
resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusForbidden {
|
||||
t.Fatal("Invalid version check: ", resp.StatusCode)
|
||||
}
|
||||
|
||||
// Check a version too large.
|
||||
resp, _ = http.Get("http://localhost:7001/version/3/check")
|
||||
resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusForbidden {
|
||||
t.Fatal("Invalid version check: ", resp.StatusCode)
|
||||
}
|
||||
|
||||
// Check a version that's just right.
|
||||
resp, _ = http.Get("http://localhost:7001/version/2/check")
|
||||
resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatal("Invalid version check: ", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,14 @@ func PutForm(url string, data url.Values) (*http.Response, error) {
|
||||
return Put(url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
|
||||
}
|
||||
|
||||
func Delete(url string, bodyType string, body io.Reader) (*http.Response, error) {
|
||||
return send("DELETE", url, bodyType, body)
|
||||
}
|
||||
|
||||
func DeleteForm(url string, data url.Values) (*http.Response, error) {
|
||||
return Delete(url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
|
||||
}
|
||||
|
||||
|
||||
func send(method string, url string, bodyType string, body io.Reader) (*http.Response, error) {
|
||||
c := NewHTTPClient()
|
||||
|
||||
@@ -5,14 +5,15 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/etcd/store"
|
||||
"github.com/coreos/etcd/server"
|
||||
"github.com/coreos/etcd/store"
|
||||
)
|
||||
|
||||
const (
|
||||
testName = "ETCDTEST"
|
||||
testName = "ETCDTEST"
|
||||
testClientURL = "localhost:4401"
|
||||
testRaftURL = "localhost:7701"
|
||||
testRaftURL = "localhost:7701"
|
||||
testSnapCount = 10000
|
||||
)
|
||||
|
||||
// Starts a server in a temporary directory.
|
||||
@@ -22,8 +23,8 @@ func RunServer(f func(*server.Server)) {
|
||||
|
||||
store := store.New()
|
||||
registry := server.NewRegistry(store)
|
||||
ps := server.NewPeerServer(testName, path, testRaftURL, testRaftURL, &server.TLSConfig{Scheme:"http"}, &server.TLSInfo{}, registry, store)
|
||||
s := server.New(testName, testClientURL, testClientURL, &server.TLSConfig{Scheme:"http"}, &server.TLSInfo{}, ps, registry, store)
|
||||
ps := server.NewPeerServer(testName, path, testRaftURL, testRaftURL, &server.TLSConfig{Scheme: "http"}, &server.TLSInfo{}, registry, store, testSnapCount)
|
||||
s := server.New(testName, testClientURL, testClientURL, &server.TLSConfig{Scheme: "http"}, &server.TLSInfo{}, ps, registry, store)
|
||||
ps.SetServer(s)
|
||||
|
||||
// Start up peer server.
|
||||
@@ -32,17 +33,17 @@ func RunServer(f func(*server.Server)) {
|
||||
c <- true
|
||||
ps.ListenAndServe(false, []string{})
|
||||
}()
|
||||
<- c
|
||||
<-c
|
||||
|
||||
// Start up etcd server.
|
||||
go func() {
|
||||
c <- true
|
||||
s.ListenAndServe()
|
||||
}()
|
||||
<- c
|
||||
<-c
|
||||
|
||||
// Wait to make sure servers have started.
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
||||
// Execute the function passed in.
|
||||
f(s)
|
||||
|
||||
Reference in New Issue
Block a user