MCPcopy Index your code
hub / github.com/coder/coder / TestServer_MultipleMessages

Function TestServer_MultipleMessages

agent/boundarylogproxy/proxy_test.go:180–230  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

178}
179
180func TestServer_MultipleMessages(t *testing.T) {
181 t.Parallel()
182
183 socketPath := filepath.Join(testutil.TempDirUnixSocket(t), "boundary.sock")
184 srv := boundarylogproxy.NewServer(testutil.Logger(t), socketPath, prometheus.NewRegistry())
185
186 ctx, cancel := context.WithCancel(context.Background())
187 defer cancel()
188
189 err := srv.Start()
190 require.NoError(t, err)
191 defer srv.Close()
192
193 reporter := &fakeReporter{}
194
195 forwarderDone := make(chan error, 1)
196 go func() {
197 forwarderDone <- srv.RunForwarder(ctx, reporter)
198 }()
199
200 conn, err := net.Dial("unix", socketPath)
201 require.NoError(t, err)
202 defer conn.Close()
203
204 // Send multiple messages and verify they are all received.
205 for range 5 {
206 req := &agentproto.ReportBoundaryLogsRequest{
207 Logs: []*agentproto.BoundaryLog{
208 {
209 Allowed: true,
210 Time: timestamppb.Now(),
211 Resource: &agentproto.BoundaryLog_HttpRequest_{
212 HttpRequest: &agentproto.BoundaryLog_HttpRequest{
213 Method: "POST",
214 Url: "https://example.com/api",
215 },
216 },
217 },
218 },
219 }
220 sendLogs(t, conn, req)
221 }
222
223 require.Eventually(t, func() bool {
224 logs := reporter.getLogs()
225 return len(logs) == 5
226 }, testutil.WaitShort, testutil.IntervalFast)
227
228 cancel()
229 <-forwarderDone
230}
231
232func TestServer_MultipleConnections(t *testing.T) {
233 t.Parallel()

Callers

nothing calls this directly

Calls 10

StartMethod · 0.95
CloseMethod · 0.95
RunForwarderMethod · 0.95
getLogsMethod · 0.95
TempDirUnixSocketFunction · 0.92
NewServerFunction · 0.92
LoggerFunction · 0.92
sendLogsFunction · 0.85
DialMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected