From 3e93b31f75510b506570f7f5ee2dbe36e2e28b5f Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Sun, 19 Sep 2021 19:24:20 +0200 Subject: [PATCH] platformtest: fix bandwidth-limiting-related panics (missing BucketCapacity in sender/receiver config) panic while running test: invalid config`Ratelimit` field invalid: BucketCapacity must not be zero main.runTestCase.func1.1 /home/cs/zrepl/zrepl/platformtest/harness/harness.go:190 runtime.gopanic /home/cs/go1.13/src/runtime/panic.go:679 github.com/zrepl/zrepl/endpoint.NewSender /home/cs/zrepl/zrepl/endpoint/endpoint.go:68 github.com/zrepl/zrepl/platformtest/tests.replicationInvocation.Do /home/cs/zrepl/zrepl/platformtest/tests/replication.go:87 github.com/zrepl/zrepl/platformtest/tests.ReplicationFailingInitialParentProhibitsChildReplication /home/cs/zrepl/zrepl/platformtest/tests/replication.go:925 main.runTestCase.func1 /home/cs/zrepl/zrepl/platformtest/harness/harness.go:193 main.runTestCase /home/cs/zrepl/zrepl/platformtest/harness/harness.go:194 main.HarnessRun /home/cs/zrepl/zrepl/platformtest/harness/harness.go:107 main.main /home/cs/zrepl/zrepl/platformtest/harness/harness.go:42 runtime.main /home/cs/go1.13/src/runtime/proc.go:203 runtime.goexit /home/cs/go1.13/src/runtime/asm_amd64.s:1357 fixup for f5f269bfd5b1641453989dd0bb9515bbb7b9e202 (bandwidth limiting) --- platformtest/tests/replication.go | 9 ++++++--- util/bandwidthlimit/bandwidthlimit.go | 7 +++++++ util/bandwidthlimit/bandwidthlimit_test.go | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 util/bandwidthlimit/bandwidthlimit_test.go diff --git a/platformtest/tests/replication.go b/platformtest/tests/replication.go index ed143c0..ebb4265 100644 --- a/platformtest/tests/replication.go +++ b/platformtest/tests/replication.go @@ -20,6 +20,7 @@ import ( "github.com/zrepl/zrepl/replication/logic" "github.com/zrepl/zrepl/replication/logic/pdu" "github.com/zrepl/zrepl/replication/report" + "github.com/zrepl/zrepl/util/bandwidthlimit" "github.com/zrepl/zrepl/util/limitio" "github.com/zrepl/zrepl/util/nodefault" "github.com/zrepl/zrepl/zfs" @@ -63,9 +64,10 @@ func (i replicationInvocation) Do(ctx *platformtest.Context) *report.Report { } senderConfig := endpoint.SenderConfig{ - FSF: i.sfilter.AsFilter(), - Encrypt: &nodefault.Bool{B: false}, - JobID: i.sjid, + FSF: i.sfilter.AsFilter(), + Encrypt: &nodefault.Bool{B: false}, + JobID: i.sjid, + BandwidthLimit: bandwidthlimit.NoLimitConfig(), } if i.senderConfigHook != nil { i.senderConfigHook(&senderConfig) @@ -75,6 +77,7 @@ func (i replicationInvocation) Do(ctx *platformtest.Context) *report.Report { JobID: i.rjid, AppendClientIdentity: false, RootWithoutClientComponent: mustDatasetPath(i.rfsRoot), + BandwidthLimit: bandwidthlimit.NoLimitConfig(), } if i.receiverConfigHook != nil { i.receiverConfigHook(&receiverConfig) diff --git a/util/bandwidthlimit/bandwidthlimit.go b/util/bandwidthlimit/bandwidthlimit.go index 24463b7..cc03a47 100644 --- a/util/bandwidthlimit/bandwidthlimit.go +++ b/util/bandwidthlimit/bandwidthlimit.go @@ -18,6 +18,13 @@ type Config struct { BucketCapacity int64 } +func NoLimitConfig() Config { + return Config{ + Max: -1, + BucketCapacity: -1, + } +} + func ValidateConfig(conf Config) error { if conf.BucketCapacity == 0 { return errors.New("BucketCapacity must not be zero") diff --git a/util/bandwidthlimit/bandwidthlimit_test.go b/util/bandwidthlimit/bandwidthlimit_test.go new file mode 100644 index 0000000..d2a16ae --- /dev/null +++ b/util/bandwidthlimit/bandwidthlimit_test.go @@ -0,0 +1,19 @@ +package bandwidthlimit + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestNoLimitConfig(t *testing.T) { + + conf := NoLimitConfig() + + err := ValidateConfig(conf) + require.NoError(t, err) + + require.NotPanics(t, func() { + _ = WrapperFromConfig(conf) + }) +}