Testing
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
||||
// BenchmarkFanOut measures the end-to-end latency and throughput of the broker
|
||||
// fan-out with varying numbers of downstream clients.
|
||||
|
||||
func BenchmarkFanOut1Client(b *testing.B) { benchFanOut(b, 1) }
|
||||
func BenchmarkFanOut1Client(b *testing.B) { benchFanOut(b, 1) }
|
||||
func BenchmarkFanOut10Clients(b *testing.B) { benchFanOut(b, 10) }
|
||||
func BenchmarkFanOut20Clients(b *testing.B) { benchFanOut(b, 20) }
|
||||
func BenchmarkFanOut100Clients(b *testing.B) { benchFanOut(b, 100) }
|
||||
|
||||
@@ -141,9 +141,9 @@ func TestStress_RapidSubscribeUnsubscribe(t *testing.T) {
|
||||
}
|
||||
|
||||
const (
|
||||
nSignals = 20
|
||||
nSignals = 20
|
||||
nGoroutines = 50
|
||||
duration = 2 * time.Second
|
||||
duration = 2 * time.Second
|
||||
)
|
||||
|
||||
brk, cancel := newBrokerN(t, nSignals)
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package broker_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/uopi/uopi/internal/broker"
|
||||
)
|
||||
|
||||
// TestDataSourcesAndSource covers the registry accessors.
|
||||
func TestDataSourcesAndSource(t *testing.T) {
|
||||
b, cancel := newBroker(t)
|
||||
defer cancel()
|
||||
|
||||
all := b.DataSources()
|
||||
if len(all) != 1 || all[0].Name() != "stub" {
|
||||
t.Fatalf("DataSources = %v, want one 'stub'", all)
|
||||
}
|
||||
if ds, ok := b.Source("stub"); !ok || ds.Name() != "stub" {
|
||||
t.Errorf("Source(stub) = %v,%v want stub,true", ds, ok)
|
||||
}
|
||||
if _, ok := b.Source("nope"); ok {
|
||||
t.Error("Source(nope): want ok=false")
|
||||
}
|
||||
}
|
||||
|
||||
// TestReadNow covers the one-shot read happy path plus the unknown-DS and
|
||||
// context-timeout error branches.
|
||||
func TestReadNow(t *testing.T) {
|
||||
b, cancel := newBroker(t)
|
||||
defer cancel()
|
||||
|
||||
ctx, c := context.WithTimeout(context.Background(), time.Second)
|
||||
defer c()
|
||||
v, err := b.ReadNow(ctx, broker.SignalRef{DS: "stub", Name: "sine_1hz"})
|
||||
if err != nil {
|
||||
t.Fatalf("ReadNow: %v", err)
|
||||
}
|
||||
if v.Timestamp.IsZero() {
|
||||
t.Error("ReadNow returned a zero-timestamp value")
|
||||
}
|
||||
|
||||
// Unknown data source.
|
||||
if _, err := b.ReadNow(ctx, broker.SignalRef{DS: "ghost", Name: "x"}); err == nil {
|
||||
t.Error("ReadNow(unknown ds): want error")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user