(ctx context.Context, t *testing.T, group *errgroup.Group, runtimePort int, externalURL, runtimeExternalURL string, logger *zap.Logger)
| 364 | } |
| 365 | |
| 366 | func 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. |
| 409 | func findTwoPorts(t *testing.T) (int, int) { |
no test coverage detected