mirror of
https://github.com/hanzoai/semantic.git
synced 2026-10-30 15:04:19 +00:00
go fix applied the modernizers. A test that printed a slice of chunks with the quoted-string verb now uses one that can render them, which is what vet was pointing at. Co-authored-by: Hanzo Dev <[email protected]>
59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
package agent
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"sync"
|
|
"testing"
|
|
)
|
|
|
|
// Every type here says it is safe for concurrent use, and an agent's context
|
|
// is shared by whatever the agent is running at once. Under -race this is the
|
|
// proof; without it, it is still a check that nothing is lost.
|
|
func TestManyAtOnce(t *testing.T) {
|
|
ctx := context.Background()
|
|
k := New()
|
|
if _, err := k.Rules.Add(lending()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
const writers = 8
|
|
const each = 25
|
|
var wg sync.WaitGroup
|
|
for w := range writers {
|
|
wg.Add(1)
|
|
go func(w int) {
|
|
defer wg.Done()
|
|
for i := range each {
|
|
who := fmt.Sprintf("%d-%d", w, i)
|
|
if _, err := k.Learn(ctx, Note{Text: "application from " + who, Of: []string{"applicant " + who}}); err != nil {
|
|
t.Error(err)
|
|
return
|
|
}
|
|
d := applicant(700, 0.3)
|
|
d.ID = "d" + who
|
|
d.Because = []string{"applicant " + who}
|
|
if _, err := k.Decide(ctx, d); err != nil {
|
|
t.Error(err)
|
|
return
|
|
}
|
|
k.Recall(ctx, "application "+who, 5)
|
|
k.Cause.Up(d.ID, 3)
|
|
k.Graph.Near("applicant "+who, Reach{Hops: 2})
|
|
k.Journal.Like(Ask{Case: "credit application", N: 3})
|
|
}
|
|
}(w)
|
|
}
|
|
wg.Wait()
|
|
|
|
if got := k.Memory.Count(); got != writers*each {
|
|
t.Errorf("%d notes kept, want %d", got, writers*each)
|
|
}
|
|
if got := len(k.Journal.All()); got != writers*each {
|
|
t.Errorf("%d decisions written, want %d", got, writers*each)
|
|
}
|
|
if got := len(k.Graph.Nodes(kindDecision)); got != writers*each {
|
|
t.Errorf("%d decisions in the graph, want %d", got, writers*each)
|
|
}
|
|
}
|