|
4 | 4 | package server
|
5 | 5 |
|
6 | 6 | import (
|
| 7 | + "fmt" |
7 | 8 | "io/ioutil"
|
8 | 9 | "net"
|
9 | 10 | "net/http"
|
@@ -380,6 +381,20 @@ func TestUpdateTrustedRoots(t *testing.T) {
|
380 | 381 | func TestConfigureClusterListener(t *testing.T) {
|
381 | 382 | logEntries := make(chan string, 100)
|
382 | 383 |
|
| 384 | + allocatePort := func() uint16 { |
| 385 | + l, err := net.Listen("tcp", "127.0.0.1:0") |
| 386 | + assert.NoError(t, err) |
| 387 | + _, portStr, err := net.SplitHostPort(l.Addr().String()) |
| 388 | + assert.NoError(t, err) |
| 389 | + port, err := strconv.ParseInt(portStr, 10, 64) |
| 390 | + assert.NoError(t, err) |
| 391 | + assert.NoError(t, l.Close()) |
| 392 | + t.Log("picked unused port", port) |
| 393 | + return uint16(port) |
| 394 | + } |
| 395 | + |
| 396 | + unUsedPort := allocatePort() |
| 397 | + |
383 | 398 | backupLogger := logger
|
384 | 399 | logger = logger.With(zap.Hooks(func(entry zapcore.Entry) error {
|
385 | 400 | logEntries <- entry.Message
|
@@ -502,15 +517,15 @@ func TestConfigureClusterListener(t *testing.T) {
|
502 | 517 | General: localconfig.General{
|
503 | 518 | Cluster: localconfig.Cluster{
|
504 | 519 | ListenAddress: "99.99.99.99",
|
505 |
| - ListenPort: 5000, |
| 520 | + ListenPort: unUsedPort, |
506 | 521 | ServerPrivateKey: "key",
|
507 | 522 | ServerCertificate: "cert",
|
508 | 523 | RootCAs: []string{"ca"},
|
509 | 524 | },
|
510 | 525 | },
|
511 | 526 | },
|
512 |
| - expectedPanic: "Failed creating gRPC server on 99.99.99.99:5000 due to " + |
513 |
| - "listen tcp 99.99.99.99:5000: bind: cannot assign requested address", |
| 527 | + expectedPanic: fmt.Sprintf("Failed creating gRPC server on 99.99.99.99:%d due "+ |
| 528 | + "to listen tcp 99.99.99.99:%d: bind: cannot assign requested address", unUsedPort, unUsedPort), |
514 | 529 | generalSrv: &comm.GRPCServer{},
|
515 | 530 | },
|
516 | 531 | {
|
|
0 commit comments