62 lines
1.2 KiB
Go
62 lines
1.2 KiB
Go
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
|
|
|
|
|
package context
|
|
|
|
import (
|
|
"testing"
|
|
"feudal/message"
|
|
)
|
|
|
|
func setupQueue() *Queue {
|
|
q := NewQueue()
|
|
return q
|
|
}
|
|
|
|
func setupBufferedQueue(size int) *Queue {
|
|
return NewBufferedQueue(size)
|
|
}
|
|
|
|
func TestNewQueue(t *testing.T) {
|
|
q := setupQueue()
|
|
if q == nil {
|
|
t.Errorf("Failed creating new queue")
|
|
}
|
|
}
|
|
|
|
func TestNewBufferedQueue(t *testing.T) {
|
|
q := setupBufferedQueue(10)
|
|
if q == nil {
|
|
t.Errorf("Failed creating new buffered queue")
|
|
}
|
|
}
|
|
|
|
func TestQueueAdd(t *testing.T) {
|
|
q := setupQueue()
|
|
var result message.Envelope
|
|
var testDispatcher DispatchReceiveFunc = func(m message.Envelope, r message.Receiver) { result = m }
|
|
|
|
q.Start(testDispatcher, nil)
|
|
q.Add(message.NewAnonymous(""))
|
|
if result.Body().(string) != "" {
|
|
t.Errorf("Failed receiving queued message")
|
|
}
|
|
}
|
|
|
|
func TestQueueRemove(t *testing.T) {
|
|
q := setupBufferedQueue(1)
|
|
q.Add(message.NewAnonymous(""))
|
|
result := q.Remove()
|
|
if result.Body().(string) != "" {
|
|
t.Errorf("Failed removing queued message")
|
|
}
|
|
}
|
|
|
|
func TestQueueMetrics(t *testing.T) {
|
|
q := setupBufferedQueue(1)
|
|
q.Add(message.NewAnonymous(""))
|
|
if q.Len() != 1 {
|
|
t.Errorf("Failed checking queue length")
|
|
}
|
|
}
|