82 lines
1.4 KiB
Go
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")
|
|
}
|
|
}
|