aboutsummaryrefslogtreecommitdiff
path: root/internal/net/server_test.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-24 22:55:35 -0400
committerhistoria <[not public]>2026-06-24 22:55:35 -0400
commit15b7e221b799ef107dec44ecdb294026dfd3d059 (patch)
tree3748e464a77f0f082bea1567e9d6990052054961 /internal/net/server_test.go
parent9d4b799db4868bcab291b83599ff088763cd4ed6 (diff)
downloadthehouseoficarus-15b7e221b799ef107dec44ecdb294026dfd3d059.tar.gz
refactor: pulled techs out to yaml files, unified numerous combat functions, broke up game object
Diffstat (limited to 'internal/net/server_test.go')
-rw-r--r--internal/net/server_test.go64
1 files changed, 64 insertions, 0 deletions
diff --git a/internal/net/server_test.go b/internal/net/server_test.go
new file mode 100644
index 0000000..fca5528
--- /dev/null
+++ b/internal/net/server_test.go
@@ -0,0 +1,64 @@
+package net
+
+import (
+ "sync"
+ "testing"
+)
+
+func TestHubConcurrency(t *testing.T) {
+ h := NewHub()
+ h.OnRemove(func(s *Session) {})
+
+ var wg sync.WaitGroup
+ const n = 50
+
+ for i := 0; i < n; i++ {
+ wg.Add(1)
+ go func() {
+ defer wg.Done()
+ s := &Session{}
+ h.Add(s)
+ h.EnterRoom(s, 1)
+ h.PlayersInRoom(1)
+ h.LeaveRoom(s)
+ h.HardRemove(s)
+ }()
+ }
+
+ for i := 0; i < n; i++ {
+ wg.Add(1)
+ go func() {
+ defer wg.Done()
+ h.AllSessions()
+ }()
+ }
+
+ wg.Wait()
+}
+
+type testConn struct{ data []byte }
+
+func (c *testConn) ReadMessage() (string, error) { return "", nil }
+func (c *testConn) Write(b []byte) (int, error) { c.data = append(c.data, b...); return len(b), nil }
+func (c *testConn) Close() error { return nil }
+func (c *testConn) SetEcho(bool) error { return nil }
+
+func TestSessionWriteConcurrency(t *testing.T) {
+ conn := &testConn{}
+ sess := &Session{Conn: conn}
+
+ var wg sync.WaitGroup
+ const n = 50
+
+ for i := 0; i < n; i++ {
+ wg.Add(1)
+ go func() {
+ defer wg.Done()
+ sess.Write("hello")
+ sess.WriteLine("world")
+ sess.Writef("formatted %d", 42)
+ }()
+ }
+
+ wg.Wait()
+}