(t *testing.T)
| 22 | ) |
| 23 | |
| 24 | func TestC_Serve(t *testing.T) { |
| 25 | var called int32 |
| 26 | c := New( |
| 27 | WithInline("http.addr", ":19998"), |
| 28 | WithInline("grpc.addr", ":19999"), |
| 29 | ) |
| 30 | c.ProvideEssentials() |
| 31 | c.AddModule(srvhttp.HealthCheckModule{}) |
| 32 | c.AddModule(srvgrpc.HealthCheckModule{}) |
| 33 | |
| 34 | c.Invoke(func(dispatcher contract.Dispatcher) { |
| 35 | dispatcher.Subscribe(events.Listen(OnHTTPServerStart, func(ctx context.Context, start interface{}) error { |
| 36 | atomic.AddInt32(&called, 1) |
| 37 | assert.Equal(t, "[::]:19998", start.(OnHTTPServerStartPayload).Listener.Addr().String()) |
| 38 | return nil |
| 39 | })) |
| 40 | }) |
| 41 | c.Invoke(func(dispatcher contract.Dispatcher) { |
| 42 | dispatcher.Subscribe(events.Listen(OnHTTPServerShutdown, func(ctx context.Context, shutdown interface{}) error { |
| 43 | atomic.AddInt32(&called, 1) |
| 44 | assert.Equal(t, "[::]:19998", shutdown.(OnHTTPServerShutdownPayload).Listener.Addr().String()) |
| 45 | return nil |
| 46 | })) |
| 47 | }) |
| 48 | c.Invoke(func(dispatcher contract.Dispatcher) { |
| 49 | dispatcher.Subscribe(events.Listen(OnGRPCServerStart, func(ctx context.Context, start interface{}) error { |
| 50 | atomic.AddInt32(&called, 1) |
| 51 | assert.Equal(t, "[::]:19999", start.(OnGRPCServerStartPayload).Listener.Addr().String()) |
| 52 | return nil |
| 53 | })) |
| 54 | }) |
| 55 | c.Invoke(func(dispatcher contract.Dispatcher) { |
| 56 | dispatcher.Subscribe(events.Listen(OnGRPCServerShutdown, func(ctx context.Context, shutdown interface{}) error { |
| 57 | atomic.AddInt32(&called, 1) |
| 58 | assert.Equal(t, "[::]:19999", shutdown.(OnGRPCServerShutdownPayload).Listener.Addr().String()) |
| 59 | return nil |
| 60 | })) |
| 61 | }) |
| 62 | ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond) |
| 63 | defer cancel() |
| 64 | e := c.Serve(ctx) |
| 65 | assert.NoError(t, e) |
| 66 | assert.Equal(t, int32(4), atomic.LoadInt32(&called)) |
| 67 | } |
| 68 | |
| 69 | func TestC_ServeDisable(t *testing.T) { |
| 70 | var called int32 |
nothing calls this directly
no test coverage detected