MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestChildTrackerBasicOperations

Function TestChildTrackerBasicOperations

server/parent_test.go:102–177  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

100 }
101 if cfg2.Users["admin"] != "supersecret" {
102 t.Error("Password not properly serialized/deserialized")
103 }
104}
105
106func TestChildTrackerBasicOperations(t *testing.T) {
107 tracker := NewChildTracker()
108
109 // Initially empty
110 if tracker.Count() != 0 {
111 t.Errorf("Expected 0 children, got %d", tracker.Count())
112 }
113
114 // Add a child
115 child1 := &ChildProcess{
116 PID: 1001,
117 Username: "user1",
118 RemoteAddr: "192.168.1.1:1111",
119 BackendKey: BackendKey{Pid: 1001, SecretKey: 111},
120 StartTime: time.Now(),
121 done: make(chan struct{}),
122 }
123 tracker.Add(child1)
124
125 if tracker.Count() != 1 {
126 t.Errorf("Expected 1 child, got %d", tracker.Count())
127 }
128
129 // Get by PID
130 got := tracker.Get(1001)
131 if got == nil {
132 t.Fatal("Expected to find child by PID")
133 return
134 } else if got.Username != "user1" {
135 t.Errorf("Username mismatch: got %q, want %q", got.Username, "user1")
136 }
137
138 // Add another child
139 child2 := &ChildProcess{
140 PID: 1002,
141 Username: "user2",
142 RemoteAddr: "192.168.1.2:2222",
143 BackendKey: BackendKey{Pid: 1002, SecretKey: 222},
144 StartTime: time.Now(),
145 done: make(chan struct{}),
146 }
147 tracker.Add(child2)
148
149 if tracker.Count() != 2 {
150 t.Errorf("Expected 2 children, got %d", tracker.Count())
151 }
152
153 // Find by backend key
154 found := tracker.FindByBackendKey(BackendKey{Pid: 1002, SecretKey: 222})
155 if found == nil {
156 t.Fatal("Expected to find child by backend key")
157 return
158 } else if found.PID != 1002 {
159 t.Errorf("PID mismatch: got %d, want %d", found.PID, 1002)

Callers

nothing calls this directly

Calls 8

CountMethod · 0.95
AddMethod · 0.95
GetMethod · 0.95
FindByBackendKeyMethod · 0.95
RemoveMethod · 0.95
NewChildTrackerFunction · 0.85
NowMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected