iop/apps/node/internal/transport/session_test.go

36 lines
792 B
Go

package transport_test
import (
"context"
"sync"
"testing"
"iop/apps/node/internal/transport"
iop "iop/proto/gen/iop"
)
type noopHandler struct{}
func (h *noopHandler) OnRunRequest(_ context.Context, _ *transport.Session, _ *iop.RunRequest) error {
return nil
}
func (h *noopHandler) OnCancel(_ context.Context, _ *transport.Session, _ *iop.CancelRequest) error {
return nil
}
func (h *noopHandler) OnCommandRequest(_ context.Context, _ *transport.Session, _ *iop.NodeCommandRequest) (*iop.NodeCommandResponse, error) {
return nil, nil
}
func TestSession_SetHandler_ConcurrentSafe(t *testing.T) {
var s transport.Session
var wg sync.WaitGroup
h := &noopHandler{}
for i := 0; i < 50; i++ {
wg.Add(1)
go func() {
defer wg.Done()
s.SetHandler(h)
}()
}
wg.Wait()
}