(t *testing.T)
| 96 | } |
| 97 | |
| 98 | func TestKernelWriteTransactionsRetryBusyLocks(t *testing.T) { |
| 99 | t.Run("Should retry PutRaw until the competing write lock is released", func(t *testing.T) { |
| 100 | t.Parallel() |
| 101 | |
| 102 | kernel, db := openLowBusyTestKernel(t) |
| 103 | ctx := testutil.Context(t) |
| 104 | holdResourceWriteLock(ctx, t, db) |
| 105 | |
| 106 | record, err := kernel.PutRaw(ctx, testDaemonActor(), RawDraft{ |
| 107 | Kind: testResourceKind, |
| 108 | ID: "busy-put", |
| 109 | Scope: ResourceScope{Kind: ResourceScopeKindGlobal}, |
| 110 | ExpectedVersion: 0, |
| 111 | SpecJSON: []byte(`{"name":"busy-put"}`), |
| 112 | }) |
| 113 | if err != nil { |
| 114 | t.Fatalf("PutRaw() error = %v", err) |
| 115 | } |
| 116 | if got, want := record.ID, "busy-put"; got != want { |
| 117 | t.Fatalf("record.ID = %q, want %q", got, want) |
| 118 | } |
| 119 | }) |
| 120 | |
| 121 | t.Run("Should retry DeleteRaw until the competing write lock is released", func(t *testing.T) { |
| 122 | t.Parallel() |
| 123 | |
| 124 | kernel, db := openLowBusyTestKernel(t) |
| 125 | ctx := testutil.Context(t) |
| 126 | record, err := kernel.PutRaw(ctx, testDaemonActor(), RawDraft{ |
| 127 | Kind: testResourceKind, |
| 128 | ID: "busy-delete", |
| 129 | Scope: ResourceScope{Kind: ResourceScopeKindGlobal}, |
| 130 | ExpectedVersion: 0, |
| 131 | SpecJSON: []byte(`{"name":"busy-delete"}`), |
| 132 | }) |
| 133 | if err != nil { |
| 134 | t.Fatalf("PutRaw(seed) error = %v", err) |
| 135 | } |
| 136 | holdResourceWriteLock(ctx, t, db) |
| 137 | |
| 138 | if err := kernel.DeleteRaw(ctx, testDaemonActor(), testResourceKind, record.ID, record.Version); err != nil { |
| 139 | t.Fatalf("DeleteRaw() error = %v", err) |
| 140 | } |
| 141 | }) |
| 142 | |
| 143 | t.Run("Should retry source snapshot writes until the competing write lock is released", func(t *testing.T) { |
| 144 | t.Parallel() |
| 145 | |
| 146 | kernel, db := openLowBusyTestKernel(t) |
| 147 | ctx := testutil.Context(t) |
| 148 | source := ResourceSource{Kind: ResourceSourceKind("extension"), ID: "busy-extension"} |
| 149 | if err := kernel.ActivateSourceSession(ctx, testDaemonActor(), source, "nonce-busy"); err != nil { |
| 150 | t.Fatalf("ActivateSourceSession() error = %v", err) |
| 151 | } |
| 152 | holdResourceWriteLock(ctx, t, db) |
| 153 | |
| 154 | err := kernel.ApplySourceSnapshotRaw( |
| 155 | ctx, |
nothing calls this directly
no test coverage detected