(t *testing.T)
| 2529 | } |
| 2530 | |
| 2531 | func TestServer_TelemetryDisabled_FinalReport(t *testing.T) { |
| 2532 | t.Parallel() |
| 2533 | |
| 2534 | telemetryServerURL, deployment, snapshot := mockTelemetryServer(t) |
| 2535 | dbConnURL, err := dbtestutil.Open(t) |
| 2536 | require.NoError(t, err) |
| 2537 | |
| 2538 | cacheDir := t.TempDir() |
| 2539 | runServer := func(t *testing.T, opts runServerOpts) (chan error, context.CancelFunc) { |
| 2540 | ctx, cancelFunc := context.WithCancel(context.Background()) |
| 2541 | inv, _ := clitest.New(t, |
| 2542 | "server", |
| 2543 | "--postgres-url", dbConnURL, |
| 2544 | "--http-address", ":0", |
| 2545 | "--access-url", "http://example.com", |
| 2546 | "--telemetry="+strconv.FormatBool(!opts.telemetryDisabled), |
| 2547 | "--telemetry-url", telemetryServerURL.String(), |
| 2548 | "--cache-dir", cacheDir, |
| 2549 | "--log-filter", ".*", |
| 2550 | ) |
| 2551 | inv.Logger = inv.Logger.Named(opts.name) |
| 2552 | |
| 2553 | errChan := make(chan error, 1) |
| 2554 | pty := ptytest.New(t).Named(opts.name).Attach(inv) |
| 2555 | go func() { |
| 2556 | errChan <- inv.WithContext(ctx).Run() |
| 2557 | // close the pty here so that we can start tearing down resources. This test creates multiple servers with |
| 2558 | // associated ptys. There is a `t.Cleanup()` that does this, but it waits until the whole test is complete. |
| 2559 | _ = pty.Close() |
| 2560 | }() |
| 2561 | |
| 2562 | if opts.waitForSnapshot { |
| 2563 | pty.ExpectMatchContext(testutil.Context(t, testutil.WaitLong), "submitted snapshot") |
| 2564 | } |
| 2565 | if opts.waitForTelemetryDisabledCheck { |
| 2566 | pty.ExpectMatchContext(testutil.Context(t, testutil.WaitLong), "finished telemetry status check") |
| 2567 | } |
| 2568 | return errChan, cancelFunc |
| 2569 | } |
| 2570 | waitForShutdown := func(t *testing.T, errChan chan error) error { |
| 2571 | t.Helper() |
| 2572 | select { |
| 2573 | case err := <-errChan: |
| 2574 | return err |
| 2575 | case <-time.After(testutil.WaitMedium): |
| 2576 | t.Fatalf("timed out waiting for server to shutdown") |
| 2577 | } |
| 2578 | return nil |
| 2579 | } |
| 2580 | |
| 2581 | errChan, cancelFunc := runServer(t, runServerOpts{ |
| 2582 | telemetryDisabled: true, waitForTelemetryDisabledCheck: true, name: "0disabled", |
| 2583 | }) |
| 2584 | cancelFunc() |
| 2585 | require.NoError(t, waitForShutdown(t, errChan)) |
| 2586 | |
| 2587 | // Since telemetry was disabled, we expect no deployments or snapshots. |
| 2588 | require.Empty(t, deployment) |
nothing calls this directly
no test coverage detected