mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
e2e/ctl_v3_alarm_test: Fix quota test
Rework the over quota test to be more a realistic test. Take into consideration that the system page size will be different across platforms. Signed-off-by: Geoff Levand <geoff@infradead.org>
This commit is contained in:
parent
8c60a532a6
commit
de8adc9e03
@ -15,44 +15,62 @@
|
||||
package e2e
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCtlV3Alarm(t *testing.T) { testCtl(t, alarmTest, withQuota(64*1024)) }
|
||||
func TestCtlV3Alarm(t *testing.T) {
|
||||
// The boltdb minimum working set is six pages.
|
||||
testCtl(t, alarmTest, withQuota(int64(13*os.Getpagesize())))
|
||||
}
|
||||
|
||||
func alarmTest(cx ctlCtx) {
|
||||
// test small put still works
|
||||
smallbuf := strings.Repeat("a", 64)
|
||||
if err := ctlV3Put(cx, "abc", smallbuf, ""); err != nil {
|
||||
if err := ctlV3Put(cx, "1st_test", 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: mvcc: database space exceeded") {
|
||||
cx.t.Fatal(err)
|
||||
// write some chunks to fill up the database
|
||||
buf := strings.Repeat("b", int(os.Getpagesize()))
|
||||
var rev int64
|
||||
for ; ; rev++ {
|
||||
if err := ctlV3Put(cx, "2nd_test", buf, ""); err != nil {
|
||||
if !strings.Contains(err.Error(), "etcdserver: mvcc: database space exceeded") {
|
||||
cx.t.Fatal(err)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// quota alarm should now be on
|
||||
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 {
|
||||
// check that Put is rejected when alarm is on
|
||||
if err := ctlV3Put(cx, "3rd_test", smallbuf, ""); err != nil {
|
||||
if !strings.Contains(err.Error(), "etcdserver: mvcc: database space exceeded") {
|
||||
cx.t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// make some space
|
||||
if err := ctlV3Compact(cx, rev, true); err != nil {
|
||||
cx.t.Fatal(err)
|
||||
}
|
||||
if err := ctlV3Defrag(cx); err != nil {
|
||||
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 {
|
||||
if err := ctlV3Put(cx, "4th_test", smallbuf, ""); err != nil {
|
||||
cx.t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user