MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / TestCluster

Function TestCluster

pkg/cluster/cluster_test.go:49–122  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

47}
48
49func 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)

Callers

nothing calls this directly

Calls 13

ContextFunction · 0.92
ServeMethod · 0.80
NewFunction · 0.70
NewMethod · 0.65
ListenMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.65
AddrMethod · 0.65
JoinMethod · 0.65
GetPeerMethod · 0.65
LeaveMethod · 0.65
ConnMethod · 0.65

Tested by

no test coverage detected