-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prepare release 0.9.0 + add test for periodic job bundle (#421)
We haven't cut a new release in a while, and the bug in #420 is kind of bad, so now that there's a fix it's not a bad time to cut a new release. I'm also including a test case that catches the bug from #420. Apparently none of our other test cases can catch the problem, so it's good to have a regression guard.
- Loading branch information
Showing
6 changed files
with
83 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package river | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/riverqueue/river/internal/maintenance" | ||
"github.com/riverqueue/river/internal/riverinternaltest" | ||
) | ||
|
||
func TestPeriodicJobBundle(t *testing.T) { | ||
t.Parallel() | ||
|
||
type testBundle struct{} | ||
|
||
setup := func(t *testing.T) (*PeriodicJobBundle, *testBundle) { | ||
t.Helper() | ||
|
||
periodicJobEnqueuer := maintenance.NewPeriodicJobEnqueuer( | ||
riverinternaltest.BaseServiceArchetype(t), | ||
&maintenance.PeriodicJobEnqueuerConfig{}, | ||
nil, | ||
) | ||
|
||
return newPeriodicJobBundle(newTestConfig(t, nil), periodicJobEnqueuer), &testBundle{} | ||
} | ||
|
||
t.Run("ConstructorFuncGeneratesNewArgsOnEachCall", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
periodicJobBundle, _ := setup(t) | ||
|
||
type TestJobArgs struct { | ||
JobArgsReflectKind[TestJobArgs] | ||
JobNum int `json:"job_num"` | ||
} | ||
|
||
var jobNum int | ||
|
||
periodicJob := NewPeriodicJob( | ||
PeriodicInterval(15*time.Minute), | ||
func() (JobArgs, *InsertOpts) { | ||
jobNum++ | ||
return TestJobArgs{JobNum: jobNum}, nil | ||
}, | ||
nil, | ||
) | ||
|
||
internalPeriodicJob := periodicJobBundle.toInternal(periodicJob) | ||
|
||
insertParams1, _, err := internalPeriodicJob.ConstructorFunc() | ||
require.NoError(t, err) | ||
require.Equal(t, 1, mustUnmarshalJSON[TestJobArgs](t, insertParams1.EncodedArgs).JobNum) | ||
|
||
insertParams2, _, err := internalPeriodicJob.ConstructorFunc() | ||
require.NoError(t, err) | ||
require.Equal(t, 2, mustUnmarshalJSON[TestJobArgs](t, insertParams2.EncodedArgs).JobNum) | ||
}) | ||
} | ||
|
||
func mustUnmarshalJSON[T any](t *testing.T, data []byte) *T { | ||
t.Helper() | ||
|
||
var val T | ||
err := json.Unmarshal(data, &val) | ||
require.NoError(t, err) | ||
return &val | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters