| 47 | } |
| 48 | |
| 49 | func TestCluster(t *testing.T) { |
| 50 | a := assertions.New(t) |
| 51 | |
| 52 | lis, err := net.Listen("tcp", "127.0.0.1:0") |
| 53 | if err != nil { |
| 54 | panic(err) |
| 55 | } |
| 56 | defer lis.Close() |
| 57 | |
| 58 | go grpc.NewServer().Serve(lis) |
| 59 | |
| 60 | config := Config{ |
| 61 | Address: lis.Addr().String(), |
| 62 | IdentityServer: lis.Addr().String(), |
| 63 | GatewayServer: lis.Addr().String(), |
| 64 | NetworkServer: lis.Addr().String(), |
| 65 | ApplicationServer: lis.Addr().String(), |
| 66 | JoinServer: lis.Addr().String(), |
| 67 | GatewayConfigurationServer: lis.Addr().String(), |
| 68 | Join: []string{lis.Addr().String()}, |
| 69 | } |
| 70 | |
| 71 | ctx := test.Context() |
| 72 | |
| 73 | c, err := New(ctx, &config) |
| 74 | a.So(err, should.BeNil) |
| 75 | |
| 76 | a.So(c.Join(), should.BeNil) |
| 77 | |
| 78 | grpc.Dial(lis.Addr().String(), grpc.WithInsecure(), grpc.WithBlock()) |
| 79 | |
| 80 | // The Identity Server playing the ACCESS role should be there within reasonable time. |
| 81 | var ac Peer |
| 82 | for range 20 { |
| 83 | time.Sleep(20 * time.Millisecond) // Wait for peers to join cluster. |
| 84 | ac, err = c.GetPeer(ctx, ttnpb.ClusterRole_ACCESS, nil) |
| 85 | if err == nil { |
| 86 | break |
| 87 | } |
| 88 | } |
| 89 | if !a.So(ac, should.NotBeNil) { |
| 90 | t.FailNow() |
| 91 | } |
| 92 | |
| 93 | er, err := c.GetPeer(ctx, ttnpb.ClusterRole_ENTITY_REGISTRY, nil) |
| 94 | a.So(er, should.NotBeNil) |
| 95 | a.So(err, should.BeNil) |
| 96 | gs, err := c.GetPeer(ctx, ttnpb.ClusterRole_GATEWAY_SERVER, nil) |
| 97 | a.So(gs, should.NotBeNil) |
| 98 | a.So(err, should.BeNil) |
| 99 | ns, err := c.GetPeer(ctx, ttnpb.ClusterRole_NETWORK_SERVER, nil) |
| 100 | a.So(ns, should.NotBeNil) |
| 101 | a.So(err, should.BeNil) |
| 102 | as, err := c.GetPeer(ctx, ttnpb.ClusterRole_APPLICATION_SERVER, nil) |
| 103 | a.So(as, should.NotBeNil) |
| 104 | a.So(err, should.BeNil) |
| 105 | js, err := c.GetPeer(ctx, ttnpb.ClusterRole_JOIN_SERVER, nil) |
| 106 | a.So(js, should.NotBeNil) |