Merge pull request #5141 from gyuho/alarm_test

e2e: test alarm
This commit is contained in:
Gyu-Ho Lee 2016-04-20 12:09:43 -07:00
commit 29dfca883f
3 changed files with 87 additions and 8 deletions

63
e2e/ctl_v3_alarm_test.go Normal file
View File

@ -0,0 +1,63 @@
// Copyright 2016 CoreOS, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package e2e
import (
"strings"
"testing"
)
func TestCtlV3Alarm(t *testing.T) { testCtl(t, alarmTest, withQuota(64*1024)) }
func alarmTest(cx ctlCtx) {
// test small put still works
smallbuf := strings.Repeat("a", int(cx.quotaBackendBytes/100))
if err := ctlV3Put(cx, "abc", smallbuf, ""); err != nil {
cx.t.Fatal(err)
}
// test big put (to be rejected, and trigger quota alarm)
bigbuf := strings.Repeat("a", int(cx.quotaBackendBytes))
if err := ctlV3Put(cx, "abc", bigbuf, ""); err != nil {
if !strings.Contains(err.Error(), "etcdserver: storage: database space exceeded") {
cx.t.Fatal(err)
}
}
if err := ctlV3Alarm(cx, "list", "alarm:NOSPACE"); err != nil {
cx.t.Fatal(err)
}
// alarm is on rejecting Puts and Txns
if err := ctlV3Put(cx, "def", smallbuf, ""); err != nil {
if !strings.Contains(err.Error(), "etcdserver: storage: database space exceeded") {
cx.t.Fatal(err)
}
}
// turn off alarm
if err := ctlV3Alarm(cx, "disarm", "alarm:NOSPACE"); err != nil {
cx.t.Fatal(err)
}
// put one more key below quota
if err := ctlV3Put(cx, "ghi", smallbuf, ""); err != nil {
cx.t.Fatal(err)
}
}
func ctlV3Alarm(cx ctlCtx, cmd string, as ...string) error {
cmdArgs := append(cx.PrefixArgs(), "alarm", cmd)
return spawnWithExpects(cmdArgs, as...)
}

View File

@ -38,8 +38,10 @@ func ctlV3Version(cx ctlCtx) error {
}
type ctlCtx struct {
t *testing.T
cfg etcdProcessClusterConfig
t *testing.T
cfg etcdProcessClusterConfig
quotaBackendBytes int64
epc *etcdProcessCluster
dialTimeout time.Duration
@ -72,6 +74,10 @@ func withInteractive() ctlOption {
return func(cx *ctlCtx) { cx.interactive = true }
}
func withQuota(b int64) ctlOption {
return func(cx *ctlCtx) { cx.quotaBackendBytes = b }
}
func testCtl(t *testing.T, testFunc func(ctlCtx), opts ...ctlOption) {
defer testutil.AfterTest(t)
@ -87,6 +93,10 @@ func testCtl(t *testing.T, testFunc func(ctlCtx), opts ...ctlOption) {
if !ret.quorum {
ret.cfg = *configStandalone(ret.cfg)
}
if ret.quotaBackendBytes > 0 {
ret.cfg.quotaBackendBytes = ret.quotaBackendBytes
}
epc, err := newEtcdProcessCluster(&ret.cfg)
if err != nil {
t.Fatalf("could not start etcd process cluster (%v)", err)

View File

@ -129,12 +129,13 @@ type etcdProcessConfig struct {
}
type etcdProcessClusterConfig struct {
clusterSize int
proxySize int
clientTLS clientConnType
isPeerTLS bool
isPeerAutoTLS bool
initialToken string
clusterSize int
proxySize int
clientTLS clientConnType
isPeerTLS bool
isPeerAutoTLS bool
initialToken string
quotaBackendBytes int64
}
// newEtcdProcessCluster launches a new cluster from etcd processes, returning
@ -238,6 +239,11 @@ func (cfg *etcdProcessClusterConfig) etcdProcessConfigs() []*etcdProcessConfig {
"--initial-cluster-token", cfg.initialToken,
"--data-dir", dataDirPath,
}
if cfg.quotaBackendBytes > 0 {
args = append(args,
"--quota-backend-bytes", fmt.Sprintf("%d", cfg.quotaBackendBytes),
)
}
args = append(args, cfg.tlsArgs()...)