Early functionality modules
0. tests for event replay Tests are now included for the event replay features. This includes many fixes on top of the last commit as well as some tweaks to config module values. 1. activity module An activity module is created to track the useractive events and provide a counter for them. It also encapsulates logic to discard old useractive events. 2. web module A web module is created. This module serves a static webpage showing runtime information. Currently it only shows a snapshot of the user activity data. It is my intention that it eventually also shows an audit log, known users and channels, uptime, and more. Future work will also be needed in order to use HTML templating so that it doesn't look so... basic. Live updates to the information may also be desired. Signed-off-by: Ava Affine <ava@sunnypup.io>
This commit is contained in:
parent
2515d396a0
commit
e7d229c217
8 changed files with 353 additions and 45 deletions
|
|
@ -2,11 +2,12 @@ package state
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitlab.com/whom/bingobot/pkg/docbuf"
|
||||
"gitlab.com/whom/bingobot/internal/logging"
|
||||
"gitlab.com/whom/bingobot/pkg/docbuf"
|
||||
)
|
||||
|
||||
/* WARNING:
|
||||
|
|
@ -54,15 +55,11 @@ func TestEventMarshalUnmarshal(t *testing.T) {
|
|||
t.Fatalf("error marshalling challenge: %e, %s", err, cstr)
|
||||
}
|
||||
|
||||
t.Logf("cstr: %s\n", cstr)
|
||||
|
||||
vstr, err := EventToString(vev);
|
||||
if err != nil {
|
||||
t.Fatalf("error marshalling vote: %e, %s", err, vstr)
|
||||
}
|
||||
|
||||
t.Logf("vstr: %s\n", vstr)
|
||||
|
||||
if ev, err := EventFromString(cstr); err != nil ||
|
||||
ev.Data()[UserEventUserKey] != cev.Data()[UserEventUserKey] ||
|
||||
ev.Data()[UserEventCreatedKey] != cev.Data()[UserEventCreatedKey] {
|
||||
|
|
@ -270,3 +267,81 @@ func TestVoteEventValidations(t *testing.T) {
|
|||
t.Errorf("Unexpected or no error: %e", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEventReplay(t *testing.T) {
|
||||
tmpTestFile, err := os.CreateTemp("", "TestEventReplayBackingStore")
|
||||
if err != nil {
|
||||
t.Fatalf("failed setting up tempfile: %s", err.Error())
|
||||
}
|
||||
|
||||
if err := tmpTestFile.Close(); err != nil {
|
||||
t.Fatalf("failed to close initial handle to tempfile: %s", err.Error())
|
||||
}
|
||||
|
||||
if err := Init(2, tmpTestFile.Name()); err != nil {
|
||||
t.Fatalf("failed initializing state machine: %s", err.Error())
|
||||
}
|
||||
|
||||
if err := PublishEvent(TestEvent{
|
||||
ID: 1,
|
||||
Dispose: true,
|
||||
}); err != nil {
|
||||
t.Fatalf("failed to publish event 1: %s", err.Error())
|
||||
}
|
||||
|
||||
if err := PublishEvent(TestEvent{
|
||||
ID: 2,
|
||||
Dispose: false,
|
||||
}); err != nil {
|
||||
t.Fatalf("failed to publish event 2: %s", err.Error())
|
||||
}
|
||||
|
||||
if err := PublishEvent(TestEvent{
|
||||
ID: 3,
|
||||
Dispose: true,
|
||||
}); err != nil {
|
||||
t.Fatalf("failed to publish event 3: %s", err.Error())
|
||||
}
|
||||
|
||||
if err := PublishEvent(TestEvent{
|
||||
ID: 4,
|
||||
Dispose: false,
|
||||
}); err != nil {
|
||||
t.Fatalf("failed to publish event 4: %s", err.Error())
|
||||
}
|
||||
|
||||
sub, err := Test.Subscribe()
|
||||
if err := Start(); err != nil {
|
||||
t.Fatalf("failed to start state machine: %s", err.Error())
|
||||
}
|
||||
|
||||
select {
|
||||
case ev1 := <- sub:
|
||||
if ev1.Type() != Test {
|
||||
t.Fatalf("wrong kind of event somehow: %+v", ev1)
|
||||
}
|
||||
if ev1.(TestEvent).ID != 2 {
|
||||
t.Fatalf("misordered event: %+v", ev1)
|
||||
}
|
||||
default:
|
||||
t.Fatal("no events available from replay")
|
||||
}
|
||||
|
||||
select {
|
||||
case ev2 := <- sub:
|
||||
if ev2.Type() != Test {
|
||||
t.Fatalf("wrong kind of event somehow: %+v", ev2)
|
||||
}
|
||||
if ev2.(TestEvent).ID != 4 {
|
||||
t.Fatalf("misordered event: %+v", ev2)
|
||||
}
|
||||
default:
|
||||
t.Fatal("only one event made it out")
|
||||
}
|
||||
|
||||
select {
|
||||
case <- sub:
|
||||
t.Fatalf("superfluous events left in subscription")
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue