Skip to content
Discussion options

You must be logged in to vote

Ah! Okay, I see what's going on here.

Yeah, since it's SQLite, you won't be able to do another DB operation from the worker unless it's sharing the transaction send to the test worker.

Below, I've copy/pasted a full example that shows how you might accomplish this by putting a transaction in your context. So in your test you'd do something like:

	// Inject the transaction into context so the worker can retrieve it.
	ctx = context.WithValue(ctx, txContextKey{}, tx)

Then in a worker:

func (w *RecordingWorker) Work(ctx context.Context, job *river.Job[RecordingArgs]) error {
	tx := ctx.Value(txContextKey{}).(pgx.Tx)

	_, err := tx.Exec(ctx, "INSERT INTO rivertest_example_audit_log (job_kind, …

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@markdboyd
Comment options

@brandur
Comment options

Answer selected by markdboyd
@markdboyd
Comment options

@brandur
Comment options

@markdboyd
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants