fix(11-08): refuse unmanaged after-commit work
This commit is contained in:
@@ -337,8 +337,8 @@ func TestSyncGates(t *testing.T) {
|
||||
}
|
||||
|
||||
// TestSyncAfterCommit covers D-20: a write syncs only after it commits
|
||||
// (lagoon.Transaction, a single statement's implicit transaction, a plain
|
||||
// gorm transaction through its handle), a rollback syncs nothing, and the
|
||||
// (lagoon.Transaction and a single statement's implicit transaction), a
|
||||
// foreign GORM transaction is refused, a rollback syncs nothing, and the
|
||||
// document is built from a reload on a clean statement.
|
||||
func TestSyncAfterCommit(t *testing.T) {
|
||||
env := newSyncEnv(t, nil, true)
|
||||
@@ -403,20 +403,22 @@ func TestSyncAfterCommit(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("plain_gorm_transaction_syncs_through_the_tx", func(t *testing.T) {
|
||||
t.Run("plain_gorm_transaction_rollback_sends_nothing", func(t *testing.T) {
|
||||
rollback := errors.New("roll back plain transaction")
|
||||
err := env.gdb.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
if err := tx.Create(&Doc{Title: "plain-tx", OwnerID: 1}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
calls := env.eng.take()
|
||||
if len(calls) != 1 || calls[0].docs[0]["title"] != "plain-tx" {
|
||||
t.Errorf("inside a plain transaction: calls = %+v, want an immediate sync from the uncommitted row", calls)
|
||||
if calls := env.eng.take(); len(calls) != 0 {
|
||||
t.Errorf("inside a plain transaction: calls = %+v, want none", calls)
|
||||
}
|
||||
// The transaction is still usable.
|
||||
return tx.Create(&Plain{Name: "after"}).Error
|
||||
return rollback
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
if !errors.Is(err, rollback) {
|
||||
t.Fatalf("err = %v", err)
|
||||
}
|
||||
if calls := env.eng.take(); len(calls) != 0 {
|
||||
t.Fatalf("after rollback: calls = %+v, want none", calls)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user