(ctx context.Context, testSetID string, testRunID string, serveTest bool)
| 933 | } |
| 934 | |
| 935 | func (r *Replayer) RunTestSet(ctx context.Context, testSetID string, testRunID string, serveTest bool) (models.TestSetStatus, error) { |
| 936 | |
| 937 | // creating error group to manage proper shutdown of all the go routines and to propagate the error to the caller |
| 938 | runTestSetErrGrp, runTestSetCtx := errgroup.WithContext(ctx) |
| 939 | runTestSetCtx = context.WithValue(runTestSetCtx, models.ErrGroupKey, runTestSetErrGrp) |
| 940 | runTestSetCtx, runTestSetCtxCancel := context.WithCancel(runTestSetCtx) |
| 941 | |
| 942 | startTime := time.Now() |
| 943 | pruneBefore := startTime.UTC() |
| 944 | |
| 945 | exitLoopChan := make(chan bool, 2) |
| 946 | defer func() { |
| 947 | // Notify the agent before cancelling the app context so proxy logs shutdown errors as debug. |
| 948 | if r.instrument && !serveTest { |
| 949 | notifyCtx, notifyCancel := context.WithTimeout(context.Background(), 10*time.Second) |
| 950 | if err := r.instrumentation.NotifyGracefulShutdown(notifyCtx); err != nil { |
| 951 | r.logger.Debug("failed to notify agent of graceful shutdown", zap.Error(err)) |
| 952 | } |
| 953 | notifyCancel() |
| 954 | } |
| 955 | runTestSetCtxCancel() |
| 956 | // Bounded drain so a wedged per-test-set goroutine can't hang teardown/SIGINT. |
| 957 | if err := utils.DrainErrGroup(r.logger, "replay-testset", runTestSetErrGrp, 30*time.Second); err != nil { |
| 958 | utils.LogError(r.logger, err, "error in testLoopErrGrp") |
| 959 | } |
| 960 | close(exitLoopChan) |
| 961 | }() |
| 962 | |
| 963 | testCases, err := r.testDB.GetTestCases(runTestSetCtx, testSetID) |
| 964 | if err != nil { |
| 965 | return models.TestSetStatusFailed, fmt.Errorf("failed to get test cases: %w", err) |
| 966 | } |
| 967 | |
| 968 | // Extract host domains from test cases for telemetry (HTTP and gRPC only) |
| 969 | if r.runDomainSet != nil { |
| 970 | for _, tc := range testCases { |
| 971 | r.runDomainSet.AddAll(telemetry.ExtractDomainsFromTestCase(tc)) |
| 972 | } |
| 973 | } |
| 974 | |
| 975 | if len(testCases) == 0 { |
| 976 | r.logger.Debug("no valid test cases found to run for test set", zap.String("test-set", testSetID)) |
| 977 | |
| 978 | testReport := &models.TestReport{ |
| 979 | Version: models.GetVersion(), |
| 980 | TestSet: testSetID, |
| 981 | Status: string(models.TestSetStatusNoTestsToRun), |
| 982 | Total: 0, |
| 983 | Ignored: 0, |
| 984 | TimeTaken: time.Since(startTime).String(), |
| 985 | CmdUsed: r.config.Test.CmdUsed, |
| 986 | } |
| 987 | err = r.reportDB.InsertReport(runTestSetCtx, testRunID, testSetID, testReport) |
| 988 | if err != nil { |
| 989 | utils.LogError(r.logger, err, "failed to insert report") |
| 990 | return models.TestSetStatusFailed, err |
| 991 | } |
| 992 | return models.TestSetStatusNoTestsToRun, nil |
no test coverage detected