@@ -16,24 +16,24 @@ type TestRunner struct {
1616 coordinator types.Coordinator
1717
1818 runIDCounter uint64
19- lastExecutedRunID uint64
2019 testSchedulerMutex sync.Mutex
2120
22- testRunMap map [uint64 ]types.Test
23- testQueue []types.TestRunner
24- testRegistryMutex sync.RWMutex
25- testNotificationChan chan bool
21+ testRunMap map [uint64 ]types.Test
22+ testQueue []types.TestRunner
23+ testRegistryMutex sync.RWMutex
24+ queueNotificationChan chan bool
25+ offQueueNotificationChan chan types.TestRunner
2626}
2727
2828func NewTestRunner (coordinator types.Coordinator , lastRunID uint64 ) * TestRunner {
2929 return & TestRunner {
30- coordinator : coordinator ,
31- runIDCounter : lastRunID ,
32- lastExecutedRunID : lastRunID ,
30+ coordinator : coordinator ,
31+ runIDCounter : lastRunID ,
3332
34- testRunMap : map [uint64 ]types.Test {},
35- testQueue : []types.TestRunner {},
36- testNotificationChan : make (chan bool , 1 ),
33+ testRunMap : map [uint64 ]types.Test {},
34+ testQueue : []types.TestRunner {},
35+ queueNotificationChan : make (chan bool , 1 ),
36+ offQueueNotificationChan : make (chan types.TestRunner , 10 ),
3737 }
3838}
3939
@@ -76,25 +76,29 @@ func (c *TestRunner) RemoveTestFromQueue(runID uint64) bool {
7676 return false
7777}
7878
79- func (c * TestRunner ) ScheduleTest (descriptor types.TestDescriptor , configOverrides map [string ]any , allowDuplicate bool ) (types.TestRunner , error ) {
79+ func (c * TestRunner ) ScheduleTest (descriptor types.TestDescriptor , configOverrides map [string ]any , allowDuplicate bool , skipQueue bool ) (types.TestRunner , error ) {
8080 if descriptor .Err () != nil {
8181 return nil , fmt .Errorf ("cannot create test from failed test descriptor: %w" , descriptor .Err ())
8282 }
8383
84- testRef , err := c .createTestRun (descriptor , configOverrides , allowDuplicate )
84+ testRef , err := c .createTestRun (descriptor , configOverrides , allowDuplicate , skipQueue )
8585 if err != nil {
8686 return nil , err
8787 }
8888
89- select {
90- case c .testNotificationChan <- true :
91- default :
89+ if skipQueue {
90+ c .offQueueNotificationChan <- testRef
91+ } else {
92+ select {
93+ case c .queueNotificationChan <- true :
94+ default :
95+ }
9296 }
9397
9498 return testRef , nil
9599}
96100
97- func (c * TestRunner ) createTestRun (descriptor types.TestDescriptor , configOverrides map [string ]any , allowDuplicate bool ) (types.TestRunner , error ) {
101+ func (c * TestRunner ) createTestRun (descriptor types.TestDescriptor , configOverrides map [string ]any , allowDuplicate bool , skipQueue bool ) (types.TestRunner , error ) {
98102 c .testSchedulerMutex .Lock ()
99103 defer c .testSchedulerMutex .Unlock ()
100104
@@ -115,7 +119,9 @@ func (c *TestRunner) createTestRun(descriptor types.TestDescriptor, configOverri
115119 }
116120
117121 c .testRegistryMutex .Lock ()
118- c .testQueue = append (c .testQueue , testRef )
122+ if ! skipQueue {
123+ c .testQueue = append (c .testQueue , testRef )
124+ }
119125 c .testRunMap [runID ] = testRef
120126 c .testRegistryMutex .Unlock ()
121127
@@ -164,7 +170,7 @@ runLoop:
164170 select {
165171 case <- ctx .Done ():
166172 break runLoop
167- case <- c .testNotificationChan :
173+ case <- c .queueNotificationChan :
168174 case <- time .After (60 * time .Second ):
169175 }
170176 }
@@ -173,9 +179,18 @@ runLoop:
173179 waitGroup .Wait ()
174180}
175181
176- func (c * TestRunner ) runTest (ctx context.Context , testRef types.TestRunner ) {
177- c .lastExecutedRunID = testRef .RunID ()
182+ func (c * TestRunner ) RunOffQueueTestExecutionLoop (ctx context.Context ) {
183+ for {
184+ select {
185+ case <- ctx .Done ():
186+ return
187+ case testRef := <- c .offQueueNotificationChan :
188+ go c .runTest (ctx , testRef )
189+ }
190+ }
191+ }
178192
193+ func (c * TestRunner ) runTest (ctx context.Context , testRef types.TestRunner ) {
179194 if err := testRef .Validate (); err != nil {
180195 testRef .Logger ().Errorf ("test validation failed: %v" , err )
181196 return
@@ -195,9 +210,10 @@ func (c *TestRunner) RunTestScheduler(ctx context.Context) {
195210
196211 // startup scheduler
197212 for _ , testDescr := range c .getStartupTests () {
198- _ , err := c .ScheduleTest (testDescr , nil , false )
213+ testConfig := testDescr .Config ()
214+ _ , err := c .ScheduleTest (testDescr , nil , false , testConfig .Schedule .SkipQueue )
199215 if err != nil {
200- c .coordinator .Logger ().Errorf ("could not schedule startup test execution for %v (%v): %v" , testDescr .ID (), testDescr . Config () .Name , err )
216+ c .coordinator .Logger ().Errorf ("could not schedule startup test execution for %v (%v): %v" , testDescr .ID (), testConfig .Name , err )
201217 }
202218 }
203219
@@ -217,9 +233,10 @@ func (c *TestRunner) RunTestScheduler(ctx context.Context) {
217233 }
218234
219235 for _ , testDescr := range c .getCronTests (cronTime ) {
220- _ , err := c .ScheduleTest (testDescr , nil , false )
236+ testConfig := testDescr .Config ()
237+ _ , err := c .ScheduleTest (testDescr , nil , false , testConfig .Schedule .SkipQueue )
221238 if err != nil {
222- c .coordinator .Logger ().Errorf ("could not schedule cron test execution for %v (%v): %v" , testDescr .ID (), testDescr . Config () .Name , err )
239+ c .coordinator .Logger ().Errorf ("could not schedule cron test execution for %v (%v): %v" , testDescr .ID (), testConfig .Name , err )
223240 }
224241 }
225242 }
0 commit comments