feudal/context/dispatcher_test.go
Matthew Rich 1b9d1b1fb1
Some checks failed
Declarative Tests / test (push) Waiting to run
Lint / golangci-lint (push) Has been cancelled
add context
2024-05-05 00:11:52 -07:00

82 lines
1.4 KiB
Go

// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
package context;
import (
"testing"
"feudal/message"
"feudal/interrogator"
"feudal/tests/receiver"
)
func TestRunner(t *testing.T) {
q := NewQueue()
q.Start(DefaultDispatcher(nil), &receiver.Ctx{})
i := interrogator.New()
q.receive <- message.New("test message", i)
r := <- i
if r.Body() != "test message" {
t.Errorf("invalid message")
}
}
func TestRunnerStartStop(t *testing.T) {
q := NewQueue()
worker := &receiver.Ctx{}
q.Start(DefaultDispatcher(worker), worker)
select {
case _, ok := <- q.receive:
if ! ok {
t.Errorf("receive channel closed")
}
default:
}
select {
case _, ok := <- q.quit:
if ! ok {
t.Errorf("quit channel closed")
}
default:
}
select {
case _, ok := <- q.stopped:
if ! ok {
t.Errorf("stopped channel closed")
}
default:
}
q.Stop()
select {
case _, ok := <- q.receive:
if ok {
t.Errorf("receive channel not closed")
}
default:
t.Errorf("receive channel not closed")
}
select {
case _, ok := <- q.quit:
if ok {
t.Errorf("quit channel not closed")
}
default:
t.Errorf("quit channel not closed")
}
select {
case _, ok := <- q.stopped:
if ok {
t.Errorf("stopped channel not closed")
}
default:
t.Errorf("stopped channel not closed")
}
}