]> git.giacomolli.uk - onechat/blobdiff - memory_test.go
Start the builds in the order of the messages
[onechat] / memory_test.go
index e8682205933daa7feefea465948b999f3f6862f4..ddbb014030f7cc26bf7f63fc5b128cb047ad05a9 100644 (file)
@@ -11,6 +11,7 @@ import (
        "strings"
        "sync"
        "testing"
+       "time"
        "unicode/utf8"
 
        "github.com/stretchr/testify/require"
@@ -105,6 +106,10 @@ func TestMemoryRunsAtMostEightBuilds(t *testing.T) {
        })
        require.Equal(t, []nodeKey{{0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}, {0, 7}}, running)
 
+       require.Eventually(t, func() bool {
+               return summarizer.Active() == maxBuilds
+       }, 10*time.Second, time.Millisecond)
+
        close(summarizer.gate)
        require.NoError(t, memory.Wait(t.Context()))
        require.Equal(t, maxBuilds, summarizer.peak)
@@ -350,6 +355,14 @@ func (f *fakeSummarizer) SetFailing(failing bool) {
        f.failing = failing
 }
 
+// Active returns the number of tasks that run now.
+func (f *fakeSummarizer) Active() int {
+       f.mutex.Lock()
+       defer f.mutex.Unlock()
+
+       return f.active
+}
+
 // Tasks returns the tasks so far.
 func (f *fakeSummarizer) Tasks() []Task {
        f.mutex.Lock()