Commit aaadde5
authored
[Fix] Fix backoff unit tests (#1387)
### Motivation
Above pr removed backoff init() strategy, which initialized a rand seed when package loaded, so that other functions can import `DefaultBackoff{}` directly.
After pr changes, there is no rand initilization by default, and we need to manually call `NewDefaultBackoff()` instead of `DefaultBackoff{}` to avoid nil issue, example output below:
```
=== RUN TestTLSConnectionCAError
time="2025-07-02T12:08:20+08:00" level=info msg="Connecting to broker" remote_addr="pulsar+ssl://localhost:6651"
time="2025-07-02T12:08:20+08:00" level=warning msg="Failed to connect to broker." error="tls: failed to verify certificate: x509: certificate is not valid for any names, but wanted to match localhost" remote_addr="pulsar+ssl://localhost:6651"
--- FAIL: TestTLSConnectionCAError (2054.87s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x5d5c3c]
goroutine 20 [running]:
testing.tRunner.func1.2({0x1780420, 0x22e2fc0})
/root/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1632 +0x49e
testing.tRunner.func1()
/root/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1635 +0x669
panic({0x1780420?, 0x22e2fc0?})
/root/go/pkg/mod/golang.org/[email protected]/src/runtime/panic.go:785 +0x136
math/rand.(*Rand).Int63(0x0)
/root/go/pkg/mod/golang.org/[email protected]/src/math/rand/rand.go:96 +0x1c
math/rand.(*Rand).Float64(0x0)
/root/go/pkg/mod/golang.org/[email protected]/src/math/rand/rand.go:207 +0x28
github.com/apache/pulsar-client-go/pulsar/backoff.(*DefaultBackoff).Next(0xc0001299e0)
/data/code/dev/pulsar-client-go/pulsar/backoff/backoff.go:66 +0xed
github.com/apache/pulsar-client-go/pulsar/internal.(*rpcClient).requestToHost.func2({0x1a17d60, 0xc0002b40d0})
/data/code/dev/pulsar-client-go/pulsar/internal/rpc_client.go:140 +0x62
github.com/apache/pulsar-client-go/pulsar/internal.Retry[...]({0x1a245d8, 0xc0000f13b0}, 0xc000059118, 0xc000059180)
/data/code/dev/pulsar-client-go/pulsar/internal/retry.go:49 +0x219
github.com/apache/pulsar-client-go/pulsar/internal.(*rpcClient).requestToHost(0xc000000300, 0xc0000f12e0, 0x1, 0x15, {0x1a18560, 0xc00012cff0})
/data/code/dev/pulsar-client-go/pulsar/internal/rpc_client.go:139 +0x3e5
github.com/apache/pulsar-client-go/pulsar/internal.(*rpcClient).RequestToAnyBroker(0xc000000300, 0x1, 0x15, {0x1a18560, 0xc00012cff0})
/data/code/dev/pulsar-client-go/pulsar/internal/rpc_client.go:150 +0xac
github.com/apache/pulsar-client-go/pulsar/internal.(*lookupService).GetPartitionedTopicMetadata(0xc0000f12d0, {0xc00032e378, 0x11})
/data/code/dev/pulsar-client-go/pulsar/internal/lookup_service.go:236 +0x28d
github.com/apache/pulsar-client-go/pulsar.(*client).TopicPartitions(0xc00033c2d0, {0xc00032e378, 0x11})
/data/code/dev/pulsar-client-go/pulsar/client_impl.go:241 +0x170
github.com/apache/pulsar-client-go/pulsar.(*producer).internalCreatePartitionsProducers(0xc0001446e0)
/data/code/dev/pulsar-client-go/pulsar/producer_impl.go:190 +0x91
github.com/apache/pulsar-client-go/pulsar.newProducer(0xc00033c2d0, 0xc000421000)
/data/code/dev/pulsar-client-go/pulsar/producer_impl.go:152 +0xd39
github.com/apache/pulsar-client-go/pulsar.(*client).CreateProducer(_, {{0xc00032e378, 0x11}, {0x0, 0x0}, 0x0, 0x0, 0x0, 0x0, 0x0, ...})
/data/code/dev/pulsar-client-go/pulsar/client_impl.go:201 +0xba
github.com/apache/pulsar-client-go/pulsar.TestTLSConnectionCAError(0xc000390b60)
/data/code/dev/pulsar-client-go/pulsar/client_impl_test.go:56 +0x1c2
testing.tRunner(0xc000390b60, 0x196b2a0)
/root/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1690 +0x1da
created by testing.(*T).Run in goroutine 1
/root/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1743 +0x7d3
```
### Modifications
Fix unit test code, replace `NewDefaultBackoff()` with `DefaultBackoff{}`1 parent 58ac256 commit aaadde5
File tree
3 files changed
+11
-6
lines changed- pulsar
- backoff
3 files changed
+11
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
47 | 49 | | |
48 | 50 | | |
49 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
50 | 55 | | |
51 | 56 | | |
52 | 57 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
150 | | - | |
| 150 | + | |
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
| |||
0 commit comments