You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I haven't fully understand some behaviors (I do not know whether they are right or wrong), so just write down the phenomenon for information.
The q2 always outputs executed2=0, has2=20, does it mean that: if no Push after the startup, the tasks in the queue would never be executed?
If the q3 uses Has to limit the tasks only being executed once (maybe like the checkAndUpdateStatus in code?), the output will be executed3=107, has3=0, it means that many tasks are still re-executed even if there is a Has check. I know that there is concurrency, but is it clear to future developers? Is the existing code like checkAndUpdateStatus which relies on Has working as expected in all cases?
Are these two behaviors by design? If yes, I think some comments would be very useful.
funcTestPullRequest_QueueBehavior(t*testing.T) {
setting_module.AppWorkPath="/tmp"_=util.RemoveAll("/tmp/data")
unittest.PrepareTestEnv(t)
setting_module.InitProviderAndLoadCommonSettingsForTest()
setting_module.LoadQueueSettings()
q1:=func() (completedTasks []string) {
startWhen100Ready:=make(chanstruct{}) // only start data cnosuming when the 100 tasks are all pushed into queuestopAt20Shutdown:=make(chanstruct{}) // stop and shutdown at the 20th itemtestHandler:=func(data...queue.Data) []queue.Data {
<-startWhen100Readytime.Sleep(100*time.Millisecond)
for_, datum:=rangedata {
s:=datum.(string)
completedTasks=append(completedTasks, s)
ifs=="task-20" {
close(stopAt20Shutdown)
returnnil
}
}
returnnil
}
q:=queue.CreateUniqueQueue("pr_patch_checker_test", testHandler, "")
q.Run(func(atShutdownfunc()) { gofunc() { <-stopAt20Shutdown; atShutdown() }() }, func(atTerminatefunc()) {})
// add 100 tasks to the queuefori:=0; i<100; i++ {
_=q.Push("task-"+strconv.Itoa(i))
}
close(startWhen100Ready)
<-stopAt20Shutdownreturn
}
q2:=func() (executedTasks []string, hasTasks []string) {
stop:=make(chanstruct{})
// collect the tasks that have been executedtestHandler:=func(data...queue.Data) []queue.Data {
for_, datum:=rangedata {
executedTasks=append(executedTasks, datum.(string))
}
returnnil
}
q:=queue.CreateUniqueQueue("pr_patch_checker_test", testHandler, "")
q.Run(func(atShutdownfunc()) { gofunc() { <-stop; atShutdown() }() }, func(atTerminatefunc()) {})
// do not push anything, just wait for a while to see whether there are tasks to get executed.time.Sleep(1*time.Second)
// check whether the tasks are still in the queuefori:=0; i<100; i++ {
ifhas, _:=q.Has("task-"+strconv.Itoa(i)); has {
hasTasks=append(hasTasks, "task-"+strconv.Itoa(i))
}
}
close(stop)
return
}
q3:=func() (executedTasks []string, hasTasks []string) {
stop:=make(chanstruct{})
varq queue.UniqueQueue// q3 test handler to use `Has` to only executed one tasktestHandler:=func(data...queue.Data) []queue.Data {
for_, datum:=rangedata {
s:=datum.(string)
ifhas, _:=q.Has(s); !has {
executedTasks=append(executedTasks, s)
}
}
returnnil
}
q=queue.CreateUniqueQueue("pr_patch_checker_test", testHandler, "")
q.Run(func(atShutdownfunc()) { gofunc() { <-stop; atShutdown() }() }, func(atTerminatefunc()) {})
// re-run all tasksfori:=0; i<100; i++ {
_=q.Push("task-"+strconv.Itoa(i))
}
// wait for a whiletime.Sleep(1*time.Second)
// check whether the tasks are still in the queuefori:=0; i<100; i++ {
ifhas, _:=q.Has("task-"+strconv.Itoa(i)); has {
hasTasks=append(hasTasks, "task-"+strconv.Itoa(i))
}
}
close(stop)
return
}
completedTasks1:=q1() // run some tasks and shutdown at an intermediate pointtime.Sleep(time.Second)
executedTasks2, hasTasks2:=q2() // restart the queue to check the tasks in ittime.Sleep(time.Second)
executedTasks3, hasTasks3:=q3() // try to re-run all taskslog.Warn("TestPullRequest_QueueStuck completed1=%v, executed2=%v, has2=%v, executed3=%v, has3=%v",
len(completedTasks1), len(executedTasks2), len(hasTasks2), len(executedTasks3), len(hasTasks3))
}
The text was updated successfully, but these errors were encountered:
This is a draft test for understanding queue's behavior (only testing, no assertion). Quote from #23050 (comment)
The output could be:
I haven't fully understand some behaviors (I do not know whether they are right or wrong), so just write down the phenomenon for information.
q2
always outputsexecuted2=0, has2=20
, does it mean that: if noPush
after the startup, the tasks in the queue would never be executed?q3
usesHas
to limit the tasks only being executed once (maybe like thecheckAndUpdateStatus
in code?), the output will beexecuted3=107, has3=0
, it means that many tasks are still re-executed even if there is aHas
check. I know that there is concurrency, but is it clear to future developers? Is the existing code likecheckAndUpdateStatus
which relies onHas
working as expected in all cases?Are these two behaviors by design? If yes, I think some comments would be very useful.
The text was updated successfully, but these errors were encountered: