snapshot of https://github.com/centrifugal/centrifugo.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
test / Lint (push) Failing after 3s
test / Test with Go 1.26.8 (push) Failing after 2s

This commit is contained in:
upstream-mirror
2026-09-16 01:17:21 +05:00
commit b352a9a30d
472 changed files with 108375 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
package controllers
import (
"regexp"
"testing"
)
// execSchemaWithRetry re-runs the whole batch on a concurrent-DDL conflict,
// which is only safe while the batch stays one implicit transaction: no
// statement of its own opening or closing a transaction, and nothing that
// cannot run inside a transaction block at all (CREATE INDEX CONCURRENTLY
// would fail outright with 25001, and a retry could not undo the half of the
// batch that already committed). The invariant lives in the SQL template, so
// pin it here rather than in a comment.
func TestControllerSchemaTemplate_StaysOneImplicitTransaction(t *testing.T) {
concurrently := regexp.MustCompile(`(?i)\bCONCURRENTLY\b`)
txControl := regexp.MustCompile(`(?im)^\s*(BEGIN|COMMIT|ROLLBACK|START\s+TRANSACTION)\b`)
sql := renderControllerTemplate(postgresControllerSchemaTemplate, "cf_")
if loc := concurrently.FindString(sql); loc != "" {
t.Errorf("schema template uses %q — it cannot run inside the implicit transaction execSchemaWithRetry relies on", loc)
}
// Only the DDL half is checked for transaction control: the funcs half is
// dollar-quoted PL/pgSQL, where BEGIN opens a block.
ddl, _ := splitControllerSchemaSQL(sql)
if loc := txControl.FindString(ddl); loc != "" {
t.Errorf("schema DDL contains explicit transaction control %q — the batch must be left to the server's implicit transaction", loc)
}
}