MCPcopy Index your code
hub / github.com/rilldata/rill / newRuntimeServer

Function newRuntimeServer

admin/testadmin/testadmin.go:366–406  ·  view source on GitHub ↗
(ctx context.Context, t *testing.T, group *errgroup.Group, runtimePort int, externalURL, runtimeExternalURL string, logger *zap.Logger)

Source from the content-addressed store, hash-verified

364}
365
366func newRuntimeServer(ctx context.Context, t *testing.T, group *errgroup.Group, runtimePort int, externalURL, runtimeExternalURL string, logger *zap.Logger) *runtimeServerFixture {
367 // Create runtime server options
368 runtimeServerOpts := &runtimeserver.Options{
369 HTTPPort: runtimePort,
370 GRPCPort: runtimePort,
371 AllowedOrigins: []string{"*"},
372 SessionKeyPairs: [][]byte{randomBytes(), randomBytes()},
373 AuthEnable: true,
374 AuthIssuerURL: externalURL, // Admin server as issuer
375 AuthAudienceURL: runtimeExternalURL, // Runtime's own URL
376 }
377
378 // Create runtime
379 rt := testruntime.New(t, false)
380
381 // Create runtime server
382 rtSrv, err := runtimeserver.NewServer(ctx, runtimeServerOpts, rt, logger, ratelimit.NewNoop(), activity.NewNoopClient())
383 require.NoError(t, err)
384 t.Cleanup(func() { rtSrv.Close() })
385
386 // Start runtime server in the background
387 group.Go(func() error {
388 return rtSrv.ServeHTTP(ctx, nil, false)
389 })
390
391 // Wait for runtime server to be ready
392 require.Eventually(t, func() bool {
393 resp, err := http.Get(fmt.Sprintf("%s/v1/ping", runtimeExternalURL))
394 if err != nil {
395 return false
396 }
397 defer resp.Body.Close()
398 return resp.StatusCode == http.StatusOK
399 }, 15*time.Second, 100*time.Millisecond, "runtime server failed to start")
400
401 return &runtimeServerFixture{
402 Runtime: rt,
403 RuntimeServer: rtSrv,
404 RuntimeServerOpts: runtimeServerOpts,
405 }
406}
407
408// findTwoPorts finds two different available ports.
409func findTwoPorts(t *testing.T) (int, int) {

Callers 1

NewWithOptionalRuntimeFunction · 0.85

Calls 9

CloseMethod · 0.95
ServeHTTPMethod · 0.95
NewFunction · 0.92
NewNoopFunction · 0.92
NewNoopClientFunction · 0.92
randomBytesFunction · 0.85
CleanupMethod · 0.65
GetMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected