|
| 1 | +// Copyright 2024 The etcd Authors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package e2e |
| 16 | + |
| 17 | +import ( |
| 18 | + "context" |
| 19 | + "fmt" |
| 20 | + "testing" |
| 21 | + "time" |
| 22 | + |
| 23 | + "github.com/stretchr/testify/require" |
| 24 | + |
| 25 | + "go.etcd.io/etcd/tests/v3/framework/e2e" |
| 26 | +) |
| 27 | + |
| 28 | +func TestDefragNoSpace(t *testing.T) { |
| 29 | + tests := []struct { |
| 30 | + name string |
| 31 | + failpoint string |
| 32 | + err string |
| 33 | + }{ |
| 34 | + { |
| 35 | + name: "no space (#18810) - can't open/create new bbolt db", |
| 36 | + failpoint: "defragOpenFileError", |
| 37 | + err: "no space", |
| 38 | + }, |
| 39 | + { |
| 40 | + name: "defragdb failure", |
| 41 | + failpoint: "defragdbFail", |
| 42 | + err: "some random error", |
| 43 | + }, |
| 44 | + } |
| 45 | + |
| 46 | + for _, tc := range tests { |
| 47 | + t.Run(tc.name, func(t *testing.T) { |
| 48 | + e2e.BeforeTest(t) |
| 49 | + |
| 50 | + clus, err := e2e.NewEtcdProcessCluster(t, |
| 51 | + &e2e.EtcdProcessClusterConfig{ |
| 52 | + ClusterSize: 1, |
| 53 | + LogLevel: "debug", |
| 54 | + GoFailEnabled: true, |
| 55 | + }, |
| 56 | + ) |
| 57 | + require.NoError(t, err) |
| 58 | + t.Cleanup(func() { clus.Stop() }) |
| 59 | + |
| 60 | + member := clus.Procs[0] |
| 61 | + etcdctl := member.Etcdctl(e2e.ClientNonTLS, false, false) |
| 62 | + |
| 63 | + require.NoError(t, member.Failpoints().SetupHTTP(context.Background(), tc.failpoint, fmt.Sprintf(`return("%s")`, tc.err))) |
| 64 | + require.ErrorContains(t, etcdctl.Defragment(time.Minute), tc.err) |
| 65 | + |
| 66 | + // Make sure etcd continues to run even after the failed defrag attempt |
| 67 | + require.NoError(t, etcdctl.Put("foo", "bar")) |
| 68 | + value, err := etcdctl.Get("foo") |
| 69 | + require.NoError(t, err) |
| 70 | + require.Len(t, value.Kvs, 1) |
| 71 | + require.Equal(t, "bar", string(value.Kvs[0].Value)) |
| 72 | + }) |
| 73 | + } |
| 74 | +} |
0 commit comments