From d976121e356d33b599008862fc5d9cb2a3004305 Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Wed, 20 Apr 2016 11:34:30 -0700 Subject: [PATCH] e2e: test alarm --- e2e/ctl_v3_alarm_test.go | 63 ++++++++++++++++++++++++++++++++++++++++ e2e/ctl_v3_test.go | 14 +++++++-- e2e/etcd_test.go | 18 ++++++++---- 3 files changed, 87 insertions(+), 8 deletions(-) create mode 100644 e2e/ctl_v3_alarm_test.go diff --git a/e2e/ctl_v3_alarm_test.go b/e2e/ctl_v3_alarm_test.go new file mode 100644 index 000000000..20fb9978b --- /dev/null +++ b/e2e/ctl_v3_alarm_test.go @@ -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...) +} diff --git a/e2e/ctl_v3_test.go b/e2e/ctl_v3_test.go index ac9d220bb..8cb7124ff 100644 --- a/e2e/ctl_v3_test.go +++ b/e2e/ctl_v3_test.go @@ -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) diff --git a/e2e/etcd_test.go b/e2e/etcd_test.go index 42993b2be..2f3e4d7d4 100644 --- a/e2e/etcd_test.go +++ b/e2e/etcd_test.go @@ -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()...)