@@ -526,20 +526,29 @@ end
526526-- Wait until the given condition is `true` (anything except `false` and `nil`).
527527-- Throws an error when the server process is terminated or timeout exceeds.
528528local function wait_for_condition (cond_desc , server , func , ...)
529+ local args = {... }
530+ local opts = {}
531+ if type (args [# args ]) == ' table' and args [# args ].save_artifacts ~= nil then
532+ opts = table.remove (args )
533+ end
529534 log .info (' Wait for %q condition for server %q (pid: %d) within %d sec' ,
530535 cond_desc , server .alias , server .process .pid , WAIT_TIMEOUT )
531536 local deadline = clock .time () + WAIT_TIMEOUT
532537 while true do
533538 if not server .process :is_alive () then
534- server :save_artifacts ()
539+ if opts .save_artifacts ~= false then
540+ server :save_artifacts ()
541+ end
535542 error ((' Process is terminated when waiting for "%s" condition for server (alias: %s, workdir: %s, pid: %d)' )
536543 :format (cond_desc , server .alias , fio .basename (server .workdir ), server .process .pid ))
537544 end
538- if func (... ) then
545+ if func (unpack ( args ) ) then
539546 return
540547 end
541548 if clock .time () > deadline then
542- server :save_artifacts ()
549+ if opts .save_artifacts ~= false then
550+ server :save_artifacts ()
551+ end
543552 error ((' Timed out to wait for "%s" condition for server (alias: %s, workdir: %s, pid: %d) within %ds' )
544553 :format (cond_desc , server .alias , fio .basename (server .workdir ), server .process .pid , WAIT_TIMEOUT ))
545554 end
@@ -563,7 +572,7 @@ function Server:stop()
563572 self .process :kill ()
564573 local ok , err = pcall (wait_for_condition , ' process is terminated' , self , function ()
565574 return not self .process :is_alive ()
566- end )
575+ end , { save_artifacts = false } )
567576 if not ok and not err :find (' Process is terminated when waiting for' ) then
568577 error (err )
569578 end
593602-- analysis if the test fails.
594603function Server :drop ()
595604 self :stop ()
596- self :save_artifacts ()
605+
606+ local current_test = rawget (_G , ' current_test' )
607+ local should_save = current_test == nil
608+
609+ if current_test then
610+ local status = current_test .status
611+ if status == ' success' or status == ' skip' or status == ' xfail' then
612+ should_save = false
613+ else
614+ should_save = true
615+ end
616+ end
617+
618+ if should_save then
619+ self :save_artifacts ()
620+ end
597621
598622 self .instance_id = nil
599623 self .instance_uuid = nil
0 commit comments