(t *testing.T)
| 131 | } |
| 132 | |
| 133 | func Test_Client_PilotUsage(t *testing.T) { |
| 134 | t.Parallel() |
| 135 | |
| 136 | ctx := context.Background() |
| 137 | |
| 138 | setup := func(t *testing.T, configMutate func(*Config)) (*Client[pgx.Tx], *pilotSpy) { |
| 139 | t.Helper() |
| 140 | |
| 141 | var ( |
| 142 | dbPool = riversharedtest.DBPool(ctx, t) |
| 143 | driver = riverpgxv5.New(dbPool) |
| 144 | schema = riverdbtest.TestSchema(ctx, t, driver, nil) |
| 145 | config = newTestConfig(t, schema) |
| 146 | ) |
| 147 | |
| 148 | if configMutate != nil { |
| 149 | configMutate(config) |
| 150 | } |
| 151 | |
| 152 | pilot := &pilotSpy{} |
| 153 | pluginDriver := newDriverWithPlugin(t, dbPool) |
| 154 | pluginDriver.pilot = pilot |
| 155 | |
| 156 | client, err := NewClient(pluginDriver, config) |
| 157 | require.NoError(t, err) |
| 158 | |
| 159 | return client, pilot |
| 160 | } |
| 161 | |
| 162 | withClientTx := func(t *testing.T, client *Client[pgx.Tx], callback func(tx pgx.Tx)) { |
| 163 | t.Helper() |
| 164 | |
| 165 | exec := client.Driver().GetExecutor() |
| 166 | execTx, err := exec.Begin(ctx) |
| 167 | require.NoError(t, err) |
| 168 | |
| 169 | committed := false |
| 170 | t.Cleanup(func() { |
| 171 | if !committed { |
| 172 | _ = execTx.Rollback(ctx) |
| 173 | } |
| 174 | }) |
| 175 | |
| 176 | tx := client.Driver().UnwrapTx(execTx) |
| 177 | callback(tx) |
| 178 | |
| 179 | require.NoError(t, execTx.Commit(ctx)) |
| 180 | committed = true |
| 181 | } |
| 182 | |
| 183 | t.Run("InitUsesPilot", func(t *testing.T) { |
| 184 | t.Parallel() |
| 185 | |
| 186 | client, pilot := setup(t, nil) |
| 187 | require.NotNil(t, client) |
| 188 | require.Equal(t, int64(1), pilot.jobCleanerQueuesExcludedCalls.Load()) |
| 189 | require.Equal(t, int64(1), pilot.pilotInitCalls.Load()) |
| 190 | }) |
nothing calls this directly
no test coverage detected
searching dependent graphs…