Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The River CLI now accepts a `--target-version` of 0 with `river migrate-down` to run all down migrations and remove all River tables (previously, -1 was used for this; -1 still works, but now 0 also works). [PR #966](https://github.com/riverqueue/river/pull/966).
- **Breaking change:** The `HookWorkEnd` interface's `WorkEnd` function now receives a `JobRow` parameter in addition to the `error` it received before. Having a `JobRow` to work with is fairly crucial to most functionality that a hook would implement, and its previous omission was entirely an error. [PR #970](https://github.com/riverqueue/river/pull/970).
- Add maximum bound to each job's `attempted_by` array so that in degenerate cases where a job is run many, many times (say it's snoozed hundreds of times), it doesn't grow to unlimited bounds. [PR #974](https://github.com/riverqueue/river/pull/974).
- A logger passed in via `river.Config` now overrides the default test-based logger when using `rivertest.NewWorker`. [PR #980](https://github.com/riverqueue/river/pull/980).

### Fixed

Expand Down
3 changes: 3 additions & 0 deletions rivertest/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ func (w *Worker[T, TTx]) workJob(ctx context.Context, tb testing.TB, tx TTx, job
exec := w.client.Driver().UnwrapExecutor(tx)
subscribeCh := make(chan []jobcompleter.CompleterJobUpdated, 1)
archetype := riversharedtest.BaseServiceArchetype(tb)
if w.config.Logger != nil {
archetype.Logger = w.config.Logger
}
if withStub, ok := timeGen.(baseservice.TimeGeneratorWithStub); ok {
archetype.Time = withStub
} else {
Expand Down
25 changes: 25 additions & 0 deletions rivertest/worker_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package rivertest

import (
"bytes"
"context"
"errors"
"log/slog"
"testing"
"time"

Expand Down Expand Up @@ -250,6 +252,29 @@ func TestWorker_Work(t *testing.T) {
require.Equal(t, river.EventKindJobCancelled, res.EventKind)
})

t.Run("UsesACustomLoggerWhenProvided", func(t *testing.T) {
t.Parallel()

bundle := setup(t)

var logBuf bytes.Buffer
bundle.config.Logger = slog.New(slog.NewTextHandler(&logBuf, &slog.HandlerOptions{
Level: slog.LevelInfo,
}))

// Return an error here because normal execution doesn't produce any
// logging that we can use to match on.
expectedErr := errors.New("my error that will be logged")
worker := river.WorkFunc(func(ctx context.Context, job *river.Job[testArgs]) error {
return expectedErr
})
tw := NewWorker(t, bundle.driver, bundle.config, worker)
_, err := tw.Work(ctx, t, bundle.tx, testArgs{Value: "test"}, nil)
require.EqualError(t, err, expectedErr.Error())

require.Contains(t, logBuf.String(), expectedErr.Error())
})

t.Run("UsesACustomClockWhenProvided", func(t *testing.T) {
t.Parallel()

Expand Down
Loading