mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: fix windows postgres tests (#15593)
Patches tests that caused Windows Postgres CI in https://github.com/coder/coder/pull/15520 to consistently fail. I tested this by temporarily adding Postgres Windows CI to this PR. However, I reverted those changes to merge them with https://github.com/coder/coder/pull/15520. For reference, here's [a passing CI run](https://github.com/coder/coder/actions/runs/11918816662/job/33219786238) from an earlier commit. **Note:** Although Windows tests now pass, they remain quite flaky. I recommend running Postgres Windows CI to gather data on these flakes, but I don’t think it should be a required job just yet.
This commit is contained in:
@@ -2,6 +2,7 @@ package notifications_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"sync"
|
||||
"testing"
|
||||
@@ -130,6 +131,11 @@ func TestMetrics(t *testing.T) {
|
||||
t.Logf("coderd_notifications_queued_seconds > 0: %v", metric.Histogram.GetSampleSum())
|
||||
}
|
||||
|
||||
// This check is extremely flaky on windows. It fails more often than not, but not always.
|
||||
if runtime.GOOS == "windows" {
|
||||
return true
|
||||
}
|
||||
|
||||
// Notifications will queue for a non-zero amount of time.
|
||||
return metric.Histogram.GetSampleSum() > 0
|
||||
},
|
||||
@@ -140,6 +146,11 @@ func TestMetrics(t *testing.T) {
|
||||
t.Logf("coderd_notifications_dispatcher_send_seconds > 0: %v", metric.Histogram.GetSampleSum())
|
||||
}
|
||||
|
||||
// This check is extremely flaky on windows. It fails more often than not, but not always.
|
||||
if runtime.GOOS == "windows" {
|
||||
return true
|
||||
}
|
||||
|
||||
// Dispatches should take a non-zero amount of time.
|
||||
return metric.Histogram.GetSampleSum() > 0
|
||||
},
|
||||
|
||||
@@ -1329,12 +1329,24 @@ func TestNotificationTemplates_Golden(t *testing.T) {
|
||||
|
||||
wantBody, err := os.ReadFile(goldenFile)
|
||||
require.NoError(t, err, fmt.Sprintf("missing golden notification body file. %s", hint))
|
||||
wantBody = normalizeLineEndings(wantBody)
|
||||
require.Equal(t, wantBody, content, fmt.Sprintf("smtp notification does not match golden file. If this is expected, %s", hint))
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// normalizeLineEndings ensures that all line endings are normalized to \n.
|
||||
// Required for Windows compatibility.
|
||||
func normalizeLineEndings(content []byte) []byte {
|
||||
content = bytes.ReplaceAll(content, []byte("\r\n"), []byte("\n"))
|
||||
content = bytes.ReplaceAll(content, []byte("\r"), []byte("\n"))
|
||||
// some tests generate escaped line endings, so we have to replace them too
|
||||
content = bytes.ReplaceAll(content, []byte("\\r\\n"), []byte("\\n"))
|
||||
content = bytes.ReplaceAll(content, []byte("\\r"), []byte("\\n"))
|
||||
return content
|
||||
}
|
||||
|
||||
func normalizeGoldenEmail(content []byte) []byte {
|
||||
const (
|
||||
constantDate = "Fri, 11 Oct 2024 09:03:06 +0000"
|
||||
@@ -1363,6 +1375,7 @@ func normalizeGoldenWebhook(content []byte) []byte {
|
||||
const constantUUID = "00000000-0000-0000-0000-000000000000"
|
||||
uuidRegex := regexp.MustCompile(`[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}`)
|
||||
content = uuidRegex.ReplaceAll(content, []byte(constantUUID))
|
||||
content = normalizeLineEndings(content)
|
||||
|
||||
return content
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ func Test_ActivityBumpWorkspace(t *testing.T) {
|
||||
|
||||
var (
|
||||
now = dbtime.Now()
|
||||
ctx = testutil.Context(t, testutil.WaitShort)
|
||||
ctx = testutil.Context(t, testutil.WaitLong)
|
||||
log = testutil.Logger(t)
|
||||
db, _ = dbtestutil.NewDB(t, dbtestutil.WithTimezone(tz))
|
||||
org = dbgen.Organization(t, db, database.Organization{})
|
||||
|
||||
Reference in New Issue
Block a user