From 8715406c8c60fb45a462845685cf75ab32b52882 Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Mon, 18 Nov 2024 12:14:08 -0500 Subject: [PATCH] Add dummy handler type for load testing --- cmd/courier/main.go | 1 + handlers/test/handler.go | 34 ++++++++++++++++++++++++++++++++++ handlers/test/handler_test.go | 26 ++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 handlers/test/handler.go create mode 100644 handlers/test/handler_test.go diff --git a/cmd/courier/main.go b/cmd/courier/main.go index df5f273a8..e673fb131 100644 --- a/cmd/courier/main.go +++ b/cmd/courier/main.go @@ -64,6 +64,7 @@ import ( _ "github.com/nyaruka/courier/handlers/start" _ "github.com/nyaruka/courier/handlers/telegram" _ "github.com/nyaruka/courier/handlers/telesom" + _ "github.com/nyaruka/courier/handlers/test" _ "github.com/nyaruka/courier/handlers/thinq" _ "github.com/nyaruka/courier/handlers/twiml" _ "github.com/nyaruka/courier/handlers/twitter" diff --git a/handlers/test/handler.go b/handlers/test/handler.go new file mode 100644 index 000000000..ae6555820 --- /dev/null +++ b/handlers/test/handler.go @@ -0,0 +1,34 @@ +package test + +import ( + "context" + "time" + + "github.com/nyaruka/courier" + "github.com/nyaruka/courier/handlers" +) + +func init() { + courier.RegisterHandler(newHandler()) +} + +type handler struct { + handlers.BaseHandler +} + +func newHandler() courier.ChannelHandler { + return &handler{handlers.NewBaseHandler(courier.ChannelType("TST"), "Test")} +} + +func (h *handler) Initialize(s courier.Server) error { + h.SetServer(s) + return nil +} + +func (h *handler) Send(ctx context.Context, msg courier.MsgOut, res *courier.SendResult, clog *courier.ChannelLog) error { + sendDelayMs := msg.Channel().IntConfigForKey("send_delay_ms", 10) + + time.Sleep(time.Duration(sendDelayMs) * time.Millisecond) + + return nil +} diff --git a/handlers/test/handler_test.go b/handlers/test/handler_test.go new file mode 100644 index 000000000..aabd31bde --- /dev/null +++ b/handlers/test/handler_test.go @@ -0,0 +1,26 @@ +package test + +import ( + "testing" + + . "github.com/nyaruka/courier/handlers" + "github.com/nyaruka/courier/test" + "github.com/nyaruka/gocommon/urns" +) + +var sendTestCases = []OutgoingTestCase{ + { + Label: "Plain Send", + MsgText: "Simple Message ☺", + MsgURN: "tel:+12067791234", + ExpectedRequests: []ExpectedRequest{}, + }, +} + +func TestOutgoing(t *testing.T) { + var channel = test.NewMockChannel("8eb23e93-5ecb-45ba-b726-3b064e0c56ab", "TST", "+12065551212", "US", + []string{urns.Phone.Prefix}, + map[string]any{}, + ) + RunOutgoingTestCases(t, channel, newHandler(), sendTestCases, nil, nil) +}