MCPcopy Create free account
hub / github.com/DoNewsCode/core / TestC_Serve

Function TestC_Serve

c_test.go:24–67  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22)
23
24func 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
69func TestC_ServeDisable(t *testing.T) {
70 var called int32

Callers

nothing calls this directly

Calls 9

ListenFunction · 0.92
WithInlineFunction · 0.85
ProvideEssentialsMethod · 0.80
InvokeMethod · 0.80
ServeMethod · 0.80
NewFunction · 0.70
SubscribeMethod · 0.65
StringMethod · 0.65
AddModuleMethod · 0.45

Tested by

no test coverage detected