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

Function TestC_ServeDisable

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

Source from the content-addressed store, hash-verified

67}
68
69func TestC_ServeDisable(t *testing.T) {
70 var called int32
71 c := New(
72 WithInline("http.disable", "true"),
73 WithInline("grpc.disable", "true"),
74 WithInline("cron.disable", "true"),
75 )
76 c.ProvideEssentials()
77 c.AddModule(srvhttp.HealthCheckModule{})
78 c.AddModule(srvgrpc.HealthCheckModule{})
79
80 c.Invoke(func(dispatcher contract.Dispatcher) {
81 dispatcher.Subscribe(events.Listen(OnHTTPServerStart, func(ctx context.Context, start interface{}) error {
82 atomic.AddInt32(&called, 1)
83 return nil
84 }))
85 })
86 c.Invoke(func(dispatcher contract.Dispatcher) {
87 dispatcher.Subscribe(events.Listen(OnHTTPServerShutdown, func(ctx context.Context, shutdown interface{}) error {
88 atomic.AddInt32(&called, 1)
89 return nil
90 }))
91 })
92 c.Invoke(func(dispatcher contract.Dispatcher) {
93 dispatcher.Subscribe(events.Listen(OnGRPCServerStart, func(ctx context.Context, start interface{}) error {
94 atomic.AddInt32(&called, 1)
95 return nil
96 }))
97 })
98 c.Invoke(func(dispatcher contract.Dispatcher) {
99 dispatcher.Subscribe(events.Listen(OnGRPCServerShutdown, func(ctx context.Context, shutdown interface{}) error {
100 atomic.AddInt32(&called, 1)
101 return nil
102 }))
103 })
104 ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
105 defer cancel()
106 e := c.Serve(ctx)
107 assert.NoError(t, e)
108 assert.Equal(t, int32(0), atomic.LoadInt32(&called))
109}
110
111func TestC_Default(t *testing.T) {
112 c := New()

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected