aboutsummaryrefslogtreecommitdiff
path: root/internal/casino/machine_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/casino/machine_test.go')
-rw-r--r--internal/casino/machine_test.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/internal/casino/machine_test.go b/internal/casino/machine_test.go
index 386e4f9..79d38fc 100644
--- a/internal/casino/machine_test.go
+++ b/internal/casino/machine_test.go
@@ -42,3 +42,56 @@ func TestMachineLeaveResetsPayoutRemainder(t *testing.T) {
t.Fatalf("payoutRemainder=%v leaked to the next player", m.payoutRemainder)
}
}
+
+func TestMachineLeaveStopsAutoBet(t *testing.T) {
+ m := newMachine(1, MachineConfig{ID: "slots", Game: GameSlots}, rand.New(rand.NewSource(7)))
+ m.player = &Participant{Name: "alice", Connected: true}
+ m.autoBet, m.autoCountdown = true, 2
+ m.leave("alice")
+ if m.autoBet || m.autoCountdown != 0 {
+ t.Fatalf("leave did not stop autobet: autoBet=%v countdown=%d", m.autoBet, m.autoCountdown)
+ }
+ if events := m.tick(); len(events) != 0 {
+ t.Fatalf("empty machine with stale autobet emitted events: %+v", events)
+ }
+}
+
+func TestMachineDisconnectFreesSeatAndForfeitsSpin(t *testing.T) {
+ m := newMachine(1, MachineConfig{ID: "slots", Game: GameSlots, SpinTicks: 1}, rand.New(rand.NewSource(7)))
+ w := &testWallet{credits: 100}
+ m.player = &Participant{Name: "alice", Connected: true, Wallet: w}
+ m.autoBet, m.autoCountdown = true, 2
+ m.spin = &SlotSpin{}
+ m.phase = machineSpinning
+ m.bet = 20
+ // Disconnect removes the player and discards the in-flight spin.
+ events := m.markDisconnected("alice")
+ if m.player != nil {
+ t.Fatal("disconnect did not free the seat")
+ }
+ if m.spin != nil || m.phase != machineReady {
+ t.Fatalf("in-flight spin was not discarded: spin=%v phase=%s", m.spin, m.phase)
+ }
+ if m.autoBet || m.autoCountdown != 0 {
+ t.Fatalf("autobet not cleared: autoBet=%v countdown=%d", m.autoBet, m.autoCountdown)
+ }
+ if m.bet != 0 || m.payoutRemainder != 0 {
+ t.Fatalf("wager state leaked: bet=%d remainder=%.2f", m.bet, m.payoutRemainder)
+ }
+ if len(events) == 0 || events[0].Type != EventLeft {
+ t.Fatalf("no public stand-up event: %+v", events)
+ }
+ // The seatel is immediately available.
+ m.join("bob")
+ if m.player == nil || m.player.Name != "bob" {
+ t.Fatalf("seat not available for the next player: player=%+v", m.player)
+ }
+ // The forfeited spin never pays out.
+ if w.paid != 0 {
+ t.Fatalf("forfeited spin paid credits: paid=%d", w.paid)
+ }
+ // The machine is idle after a disconnect.
+ if events := m.tick(); len(events) != 0 {
+ t.Fatalf("empty machine emitted events after disconnect: %+v", events)
+ }
+}