forked from flyteorg/flyte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added start time for supporting restarts for fixed rate schedules (fl…
…yteorg#476) * Added race skip check Signed-off-by: Prafulla Mahindrakar <[email protected]> * lint Signed-off-by: Prafulla Mahindrakar <[email protected]> * Fixed unit tests Signed-off-by: pmahindrakar-oss <[email protected]> * Moved to integration test Signed-off-by: pmahindrakar-oss <[email protected]> * refactored integration test Signed-off-by: pmahindrakar-oss <[email protected]> * nit : rename to lastTime Signed-off-by: pmahindrakar-oss <[email protected]> * nit : revert Signed-off-by: pmahindrakar-oss <[email protected]> * lastTime -> lastExecTime Signed-off-by: pmahindrakar-oss <[email protected]> * integration test tag Signed-off-by: pmahindrakar-oss <[email protected]> --------- Signed-off-by: Prafulla Mahindrakar <[email protected]> Signed-off-by: pmahindrakar-oss <[email protected]> Signed-off-by: eduardo apolinario <[email protected]> Co-authored-by: eduardo apolinario <[email protected]>
- Loading branch information
1 parent
00915ec
commit 507ad44
Showing
7 changed files
with
133 additions
and
28 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
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
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,95 @@ | ||
//go:build integration | ||
// +build integration | ||
|
||
package tests | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
"testing" | ||
"time" | ||
|
||
"github.com/robfig/cron/v3" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
"golang.org/x/time/rate" | ||
|
||
adminModels "github.com/flyteorg/flyteadmin/pkg/repositories/models" | ||
"github.com/flyteorg/flyteadmin/pkg/runtime" | ||
scheduler "github.com/flyteorg/flyteadmin/scheduler/core" | ||
"github.com/flyteorg/flyteadmin/scheduler/executor/mocks" | ||
"github.com/flyteorg/flyteadmin/scheduler/repositories/models" | ||
"github.com/flyteorg/flyteadmin/scheduler/snapshoter" | ||
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" | ||
"github.com/flyteorg/flytestdlib/promutils" | ||
) | ||
|
||
func TestScheduleJob(t *testing.T) { | ||
ctx := context.Background() | ||
True := true | ||
now := time.Now() | ||
scheduleFixed := models.SchedulableEntity{ | ||
BaseModel: adminModels.BaseModel{ | ||
UpdatedAt: now, | ||
}, | ||
SchedulableEntityKey: models.SchedulableEntityKey{ | ||
Project: "project", | ||
Domain: "domain", | ||
Name: "fixed1", | ||
Version: "version1", | ||
}, | ||
FixedRateValue: 1, | ||
Unit: admin.FixedRateUnit_MINUTE, | ||
Active: &True, | ||
} | ||
|
||
c := cron.New() | ||
configuration := runtime.NewConfigurationProvider() | ||
applicationConfiguration := configuration.ApplicationConfiguration().GetTopLevelConfig() | ||
schedulerScope := promutils.NewScope(applicationConfiguration.MetricsScope).NewSubScope("schedule_job") | ||
rateLimiter := rate.NewLimiter(1, 10) | ||
executor := new(mocks.Executor) | ||
snapshot := &snapshoter.SnapshotV1{} | ||
executor.OnExecuteMatch(mock.Anything, mock.Anything, mock.Anything).Return(nil) | ||
g := scheduler.NewGoCronScheduler(context.Background(), []models.SchedulableEntity{}, schedulerScope, snapshot, rateLimiter, executor, false) | ||
c.Start() | ||
|
||
tests := []struct { | ||
testName string | ||
lastExecTime *time.Time | ||
assertionFunc func(t assert.TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool | ||
}{ | ||
{testName: "using_schedule_time", lastExecTime: &now, assertionFunc: assert.Equal}, | ||
{testName: "without_schedule_time", lastExecTime: nil, assertionFunc: assert.NotEqual}, | ||
} | ||
wg := &sync.WaitGroup{} | ||
for _, tc := range tests { | ||
t.Run(tc.testName, func(t *testing.T) { | ||
wg.Add(1) | ||
timedFuncWithSchedule := func(jobCtx context.Context, schedule models.SchedulableEntity, scheduleTime time.Time) error { | ||
tc.assertionFunc(t, now, scheduleTime) | ||
wg.Done() | ||
return nil | ||
} | ||
err := g.ScheduleJob(ctx, scheduleFixed, timedFuncWithSchedule, tc.lastExecTime) | ||
assert.NoError(t, err) | ||
}) | ||
} | ||
|
||
select { | ||
case <-time.After(time.Minute * 2): | ||
assert.Fail(t, "timed job didn't get triggered") | ||
case <-wait(wg): | ||
c.Stop() | ||
break | ||
} | ||
} | ||
|
||
func wait(wg *sync.WaitGroup) chan bool { | ||
ch := make(chan bool) | ||
go func() { | ||
wg.Wait() | ||
ch <- true | ||
}() | ||
return ch | ||
} |