Skip to content

Commit 56feeea

Browse files
authored
Merge branch 'main' into copilot/fix-3611
2 parents dca924d + 30dee26 commit 56feeea

File tree

3 files changed

+68
-2
lines changed

3 files changed

+68
-2
lines changed

addon/retry/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ func configDefault(config ...Config) Config {
6161
if cfg.MaxRetryCount <= 0 {
6262
cfg.MaxRetryCount = DefaultConfig.MaxRetryCount
6363
}
64-
if cfg.currentInterval != cfg.InitialInterval {
65-
cfg.currentInterval = DefaultConfig.currentInterval
64+
if cfg.currentInterval == 0 {
65+
cfg.currentInterval = cfg.InitialInterval
6666
}
6767
return cfg
6868
}

addon/retry/config_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,39 @@ func TestConfigDefault_PartialAndNegative(t *testing.T) {
3131
cfg := configDefault(Config{Multiplier: -1, MaxRetryCount: 0})
3232
require.Equal(t, DefaultConfig, cfg)
3333
}
34+
35+
func TestConfigDefault_CustomInitialInterval(t *testing.T) {
36+
t.Parallel()
37+
38+
cfg := configDefault(Config{InitialInterval: 5 * time.Second})
39+
40+
require.Equal(t, 5*time.Second, cfg.currentInterval)
41+
require.Equal(t, 5*time.Second, cfg.InitialInterval)
42+
}
43+
44+
func TestConfigDefault_CustomCurrentInterval(t *testing.T) {
45+
t.Parallel()
46+
47+
cfg := configDefault(Config{currentInterval: 3 * time.Second})
48+
49+
require.Equal(t, 3*time.Second, cfg.currentInterval)
50+
require.Equal(t, DefaultConfig.InitialInterval, cfg.InitialInterval)
51+
}
52+
53+
func TestConfigDefault_CurrentIntervalAndInitialDiffer(t *testing.T) {
54+
t.Parallel()
55+
56+
cfg := configDefault(Config{InitialInterval: 5 * time.Second, currentInterval: 3 * time.Second})
57+
58+
require.Equal(t, 5*time.Second, cfg.InitialInterval)
59+
require.Equal(t, 3*time.Second, cfg.currentInterval)
60+
}
61+
62+
func TestNewExponentialBackoff_Config(t *testing.T) {
63+
t.Parallel()
64+
65+
backoff := NewExponentialBackoff(Config{InitialInterval: 4 * time.Second})
66+
67+
require.Equal(t, 4*time.Second, backoff.InitialInterval)
68+
require.Equal(t, 4*time.Second, backoff.currentInterval)
69+
}

helpers_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,7 @@ func Benchmark_GenericParseTypeFloats(b *testing.B) {
11811181

11821182
// go test -v -run=^$ -bench=Benchmark_GenericParseTypeBytes -benchmem -count=4
11831183
func Benchmark_GenericParseTypeBytes(b *testing.B) {
1184+
b.Skip("Skipped: too fast to compare reliably (results in sub-ns range are unstable)")
11841185
cases := []struct {
11851186
str string
11861187
err error
@@ -1228,6 +1229,7 @@ func Benchmark_GenericParseTypeBytes(b *testing.B) {
12281229

12291230
// go test -v -run=^$ -bench=Benchmark_GenericParseTypeString -benchmem -count=4
12301231
func Benchmark_GenericParseTypeString(b *testing.B) {
1232+
b.Skip("Skipped: too fast to compare reliably (results in sub-ns range are unstable)")
12311233
tests := []string{"john", "doe", "hello", "fiber"}
12321234

12331235
for _, test := range tests {
@@ -1249,6 +1251,7 @@ func Benchmark_GenericParseTypeString(b *testing.B) {
12491251

12501252
// go test -v -run=^$ -bench=Benchmark_GenericParseTypeBoolean -benchmem -count=4
12511253
func Benchmark_GenericParseTypeBoolean(b *testing.B) {
1254+
b.Skip("Skipped: too fast to compare reliably (results in sub-ns range are unstable)")
12521255
bools := []struct {
12531256
str string
12541257
value bool
@@ -1385,3 +1388,30 @@ func Test_IsEtagStale(t *testing.T) {
13851388
// Weak vs. weak
13861389
require.False(t, app.isEtagStale(`W/"a"`, []byte(`W/"a"`)))
13871390
}
1391+
1392+
func Test_App_quoteRawString(t *testing.T) {
1393+
t.Parallel()
1394+
1395+
cases := []struct {
1396+
name string
1397+
in string
1398+
out string
1399+
}{
1400+
{"empty", "", ""},
1401+
{"simple", "simple", "simple"},
1402+
{"backslash", "A\\B", "A\\\\B"},
1403+
{"quote", `He said "Yo"`, `He said \"Yo\"`},
1404+
{"newline", "Hello\n", "Hello\\n"},
1405+
{"carriage", "Hello\r", "Hello\\r"},
1406+
{"controls", string([]byte{0, 31, 127}), "%00%1F%7F"},
1407+
{"mixed", "test \"A\n\r" + string([]byte{1}) + "\\", `test \"A\n\r%01\\`},
1408+
}
1409+
1410+
for _, tc := range cases {
1411+
t.Run(tc.name, func(t *testing.T) {
1412+
t.Parallel()
1413+
app := New()
1414+
require.Equal(t, tc.out, app.quoteRawString(tc.in))
1415+
})
1416+
}
1417+
}

0 commit comments

Comments
 (0)