-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathserver_round_testhook_test.go
More file actions
68 lines (54 loc) · 1.8 KB
/
Copy pathserver_round_testhook_test.go
File metadata and controls
68 lines (54 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package waved
import (
"context"
"testing"
"github.com/lightninglabs/wavelength/baselib/actor"
"github.com/lightninglabs/wavelength/lib/actormsg"
"github.com/lightninglabs/wavelength/round"
fn "github.com/lightningnetwork/lnd/fn/v2"
"github.com/stretchr/testify/require"
)
// TestServerTriggerRoundRegistrationRequiresActorSystem verifies the harness
// helper fails fast before daemon startup has initialized the actor system.
func TestServerTriggerRoundRegistrationRequiresActorSystem(t *testing.T) {
t.Parallel()
server := &Server{}
err := server.TriggerRoundRegistration(t.Context())
require.EqualError(t, err, "actor system not initialized")
}
// TestServerTriggerRoundRegistration verifies the helper injects the expected
// IntentRequested event through the round actor service key.
func TestServerTriggerRoundRegistration(t *testing.T) {
t.Parallel()
system := actor.NewActorSystem()
defer func() {
err := system.Shutdown(t.Context())
require.NoError(t, err)
}()
delivered := make(chan *round.ServerMessageNotification, 1)
key := round.NewServiceKey()
behavior := actor.NewFunctionBehavior(
func(_ context.Context,
msg actormsg.RoundReceivable,
) fn.Result[actormsg.RoundActorResp] {
notif, ok := msg.(*round.ServerMessageNotification)
require.True(
t, ok, "expected server notification, got %T",
msg,
)
delivered <- notif
return fn.Ok[actormsg.RoundActorResp](
&round.ServerMessageResponse{},
)
},
)
_ = actor.RegisterWithSystem(system, "round-under-test", key, behavior)
server := &Server{actorSystem: system}
require.NoError(t, server.TriggerRoundRegistration(t.Context()))
select {
case notif := <-delivered:
require.IsType(t, &round.IntentRequested{}, notif.Message)
case <-t.Context().Done():
t.Fatal("round registration was not delivered")
}
}