Skip to content

Commit 5e0a349

Browse files
danceratopzmarioevz
authored andcommitted
Clean-up shared client containers on test suite end
1 parent 4dbaf86 commit 5e0a349

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

internal/libhive/testmanager.go

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,14 @@ func filterClientDesignators(clients []ClientDesignator) []ClientDesignator {
106106
DockerfileExt: client.DockerfileExt,
107107
BuildArgs: make(map[string]string),
108108
}
109-
109+
110110
// Filter build args
111111
for key, value := range client.BuildArgs {
112112
if !excludedBuildArgs[key] {
113113
filteredClient.BuildArgs[key] = value
114114
}
115115
}
116-
116+
117117
filtered[i] = filteredClient
118118
}
119119
return filtered
@@ -123,10 +123,10 @@ func NewTestManager(config SimEnv, b ContainerBackend, clients []*ClientDefiniti
123123
if hiveInfo.Commit == "" && hiveInfo.Date == "" {
124124
hiveInfo.Commit, hiveInfo.Date = hiveVersion()
125125
}
126-
126+
127127
// Filter sensitive build args from HiveInfo.ClientFile
128128
hiveInfo.ClientFile = filterClientDesignators(hiveInfo.ClientFile)
129-
129+
130130
return &TestManager{
131131
clientDefs: clients,
132132
config: config,
@@ -398,29 +398,44 @@ func (manager *TestManager) doEndSuite(testSuite TestSuiteID) error {
398398
if suite.testDetailsFile != nil {
399399
suite.testDetailsFile.Close()
400400
}
401-
401+
402402
// Create comprehensive run metadata
403403
runMetadata := &RunMetadata{
404404
HiveCommand: manager.hiveInfo.Command,
405405
HiveVersion: GetHiveVersion(),
406406
}
407-
407+
408408
// Add client configuration if available
409409
if manager.hiveInfo.ClientFilePath != "" && len(manager.hiveInfo.ClientFile) > 0 {
410410
// Convert existing ClientFile data to consistent format for storage
411411
clientConfigContent := map[string]interface{}{
412412
"clients": manager.hiveInfo.ClientFile,
413413
}
414-
414+
415415
runMetadata.ClientConfig = &ClientConfigInfo{
416416
FilePath: manager.hiveInfo.ClientFilePath,
417417
Content: clientConfigContent,
418418
}
419419
}
420-
420+
421421
// Attach metadata to suite
422422
suite.RunMetadata = runMetadata
423-
423+
424+
// Clean up any shared clients for this suite.
425+
if suite.SharedClients != nil {
426+
for nodeID, clientInfo := range suite.SharedClients {
427+
// Stop the container if it's still running.
428+
if clientInfo.wait != nil {
429+
slog.Info("cleaning up shared client", "suite", testSuite, "client", clientInfo.Name, "container", nodeID[:8])
430+
if err := manager.backend.DeleteContainer(clientInfo.ID); err != nil {
431+
slog.Error("could not stop shared client", "suite", testSuite, "container", nodeID[:8], "err", err)
432+
}
433+
clientInfo.wait()
434+
clientInfo.wait = nil
435+
}
436+
}
437+
}
438+
424439
// Write the result.
425440
if manager.config.LogDir != "" {
426441
err := writeSuiteFile(suite, manager.config.LogDir)
@@ -565,7 +580,7 @@ func (manager *TestManager) EndTest(suiteID TestSuiteID, testID TestID, result *
565580
if err == nil {
566581
defer targetFile.Close()
567582
sourceFile.Seek(clientInfo.LogPosition, 0)
568-
io.CopyN(targetFile, sourceFile, currentPosition - clientInfo.LogPosition)
583+
io.CopyN(targetFile, sourceFile, currentPosition-clientInfo.LogPosition)
569584
relativePath := filepath.Join("shared_clients",
570585
fmt.Sprintf("%d-%s-test%d.log", time.Now().Unix(), nodeID, testID))
571586
testCase.ClientInfo[nodeID].LogFile = relativePath
@@ -790,16 +805,15 @@ func (manager *TestManager) UnpauseNode(testID TestID, nodeID string) error {
790805
// writeSuiteFile writes the simulation result to the log directory.
791806
// List of build arguments to exclude from result JSON for security/privacy
792807
var excludedBuildArgs = map[string]bool{
793-
"GOPROXY": true, // Go proxy URLs may contain sensitive info
794-
"GITHUB_TOKEN": true, // GitHub tokens
795-
"ACCESS_TOKEN": true, // Generic access tokens
796-
"API_KEY": true, // API keys
797-
"PASSWORD": true, // Passwords
798-
"SECRET": true, // Generic secrets
799-
"TOKEN": true, // Generic tokens
808+
"GOPROXY": true, // Go proxy URLs may contain sensitive info
809+
"GITHUB_TOKEN": true, // GitHub tokens
810+
"ACCESS_TOKEN": true, // Generic access tokens
811+
"API_KEY": true, // API keys
812+
"PASSWORD": true, // Passwords
813+
"SECRET": true, // Generic secrets
814+
"TOKEN": true, // Generic tokens
800815
}
801816

802-
803817
func writeSuiteFile(s *TestSuite, logdir string) error {
804818
suiteData, err := json.Marshal(s)
805819
if err != nil {

0 commit comments

Comments
 (0)