Skip to content

Commit 16158ba

Browse files
author
Charlie Egan
authored
runtime: Update server init check (#7818)
I saw a panic here: https://github.com/open-policy-agent/opa/actions/runs/16652495113/job/47128828522 and think it's related to the server init check returning before the addrs are set. I update all cases where a similar check on logs is done. I am unsure how the log could come before the server is initialized, but sometimes funny things happen in race detector ordering and this looks more correct to me. Signed-off-by: Charlie Egan <[email protected]>
1 parent 6543cdf commit 16158ba

File tree

1 file changed

+5
-25
lines changed

1 file changed

+5
-25
lines changed

v1/runtime/runtime_test.go

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -618,11 +618,7 @@ p contains 1 if {
618618
go rt.StartServer(ctx)
619619

620620
if !test.Eventually(t, 5*time.Second, func() bool {
621-
found := false
622-
for _, e := range testLogger.Entries() {
623-
found = strings.Contains(e.Message, "Server initialized.") || found
624-
}
625-
return found
621+
return rt.ServerStatus() == ServerInitialized && len(rt.Addrs()) > 0
626622
}) {
627623
t.Fatal("Timed out waiting for server to start")
628624
}
@@ -1816,11 +1812,7 @@ func TestCustomHandlerFlusher(t *testing.T) {
18161812
}
18171813
go rt.StartServer(ctx)
18181814
if !test.Eventually(t, 5*time.Second, func() bool {
1819-
found := false
1820-
for _, e := range testLogger.Entries() {
1821-
found = strings.Contains(e.Message, "Server initialized.") || found
1822-
}
1823-
return found
1815+
return rt.ServerStatus() == ServerInitialized && len(rt.Addrs()) > 0
18241816
}) {
18251817
t.Fatal("Timed out waiting for server to start")
18261818
}
@@ -2024,11 +2016,7 @@ func TestCustomStoreBuilder(t *testing.T) {
20242016
}
20252017
go rt.StartServer(ctx)
20262018
if !test.Eventually(t, 5*time.Second, func() bool {
2027-
found := false
2028-
for _, e := range testLogger.Entries() {
2029-
found = strings.Contains(e.Message, "Server initialized.") || found
2030-
}
2031-
return found
2019+
return rt.ServerStatus() == ServerInitialized && len(rt.Addrs()) > 0
20322020
}) {
20332021
t.Fatal("Timed out waiting for server to start")
20342022
}
@@ -2079,11 +2067,7 @@ func TestExtraMiddleware(t *testing.T) {
20792067
}))
20802068
go rt.StartServer(ctx)
20812069
if !test.Eventually(t, 5*time.Second, func() bool {
2082-
found := false
2083-
for _, e := range testLogger.Entries() {
2084-
found = strings.Contains(e.Message, "Server initialized.") || found
2085-
}
2086-
return found
2070+
return rt.ServerStatus() == ServerInitialized && len(rt.Addrs()) > 0
20872071
}) {
20882072
t.Fatal("Timed out waiting for server to start")
20892073
}
@@ -2158,11 +2142,7 @@ allow if {
21582142
})
21592143
go rt.StartServer(ctx)
21602144
if !test.Eventually(t, 5*time.Second, func() bool {
2161-
found := false
2162-
for _, e := range testLogger.Entries() {
2163-
found = strings.Contains(e.Message, "Server initialized.") || found
2164-
}
2165-
return found
2145+
return rt.ServerStatus() == ServerInitialized && len(rt.Addrs()) > 0
21662146
}) {
21672147
t.Fatal("Timed out waiting for server to start")
21682148
}

0 commit comments

Comments
 (0)