Skip to content

Commit

Permalink
test dual kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
fogfish committed Sep 28, 2024
1 parent ce1e22e commit ed446a3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
9 changes: 9 additions & 0 deletions kernel/cathode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ func TestDequeuer(t *testing.T) {
[]swarm.Bag{{Ctx: &swarm.Context{Category: "test", Digest: "1"}, Object: []byte(`"1"`)}},
)

t.Run("Kernel", func(t *testing.T) {
k := New(nil, NewDequeuer(mockCathode(nil, nil), swarm.Config{}))
go func() {
time.Sleep(yield_before_close)
k.Close()
}()
k.Await()
})

t.Run("None", func(t *testing.T) {
k := NewDequeuer(none, swarm.Config{PollFrequency: 1 * time.Second})
go k.Await()
Expand Down
12 changes: 9 additions & 3 deletions kernel/emitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ import (
)

func TestEnqueuer(t *testing.T) {
// none := mockEmitter(0, nil)
// pass := mockEmitter(10, make(chan []byte))

mockit := func(config swarm.Config) (*Enqueuer, *emitter) {
mock := mockEmitter(10)
k := NewEnqueuer(mock, config)
Expand All @@ -34,6 +31,15 @@ func TestEnqueuer(t *testing.T) {
return k, mock
}

t.Run("Kernel", func(t *testing.T) {
k := New(NewEnqueuer(mockEmitter(10), swarm.Config{}), nil)
go func() {
time.Sleep(yield_before_close)
k.Close()
}()
k.Await()
})

t.Run("None", func(t *testing.T) {
k, _ := mockit(swarm.Config{})
Enqueue(k, "test", swarm.NewCodecJson[string]())
Expand Down
18 changes: 14 additions & 4 deletions kernel/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,21 @@ func New(enqueuer *Enqueuer, dequeuer *Dequeuer) *Kernel {
}

func (k *Kernel) Close() {
k.Dequeuer.Close()
k.Enqueuer.Close()
if k.Dequeuer != nil {
k.Dequeuer.Close()
}

if k.Enqueuer != nil {
k.Enqueuer.Close()
}
}

func (k *Kernel) Await() {
k.Dequeuer.Await()
k.Enqueuer.Await()
if k.Dequeuer != nil {
k.Dequeuer.Await()
}

if k.Enqueuer != nil {
k.Enqueuer.Await()
}
}

0 comments on commit ed446a3

Please sign in to comment.