package test
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/require"
amhist "github.com/pancsta/asyncmachine-go/pkg/history"
amss "github.com/pancsta/asyncmachine-go/pkg/states"
)
var ss = amss .BasicStates
func AssertBasics (t *testing .T , mem amhist .MemoryApi , rounds int ) {
ctx := context .Background ()
mach := mem .Machine ()
start := time .Now ()
require .True (t , mach .Has (ss .Names ()), "Machine has to implement BasicStates" )
require .True (t , mem .IsTracked1 (ss .Start ), "Start should be tracked" )
require .False (t , mem .IsTracked1 (ss .Ready ), "Ready should not be tracked" )
t .Logf ("rounds: %d" , rounds )
for range rounds {
mach .Toggle1 (ss .Start , nil )
}
t .Logf ("mach: %s" , time .Since (start ))
require .NoError (t , mem .Sync ())
t .Logf ("db: %s" , time .Since (start ))
machRec := mem .MachineRecord ()
require .NotNil (t , machRec , "Machine record is not nil" )
latest , err := mem .FindLatest (ctx , false , 25 , amhist .Query {})
require .NoError (t , err )
require .Len (t , latest , 25 , "25 rows returned" )
require .Equal (t , int (machRec .NextId )-24 , int (latest [23 ].Time .MTimeSum ),
"time sum matches" )
require .Equal (t , int (machRec .NextId )-25 , int (latest [24 ].Time .MTimeSum ),
"time sum matches" )
t .Logf ("query: %s" , time .Since (start ))
}
func AssertGc (t *testing .T , mem amhist .MemoryApi , rounds int ) {
ctx := context .Background ()
all , err := mem .FindLatest (ctx , false , mem .Config ().MaxRecords *2 ,
amhist .Query {})
require .NoError (t , err )
require .LessOrEqual (t , len (all ), mem .Config ().MaxRecords ,
"max records respected" )
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .