forked from dapr/dapr
-
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.
Jobs: Return Job execution SUCCESS/FAILURE (dapr#8240)
* Jobs: Return Job execution SUCCESS/FAILURE Returns the job execution result to scheduler (SUCCESS/FAILURE) to correctly trigger failure policy if required. Adds daprd jobs/actor reminder failure policy integration tests. Adds test to job execution to ensure NotFound HTTP status is treated as SUCCESS as it is "not retry-able". Signed-off-by: joshvanl <me@joshvanl.dev> * Update diagridio/go-etcd-cron to master HEAD Signed-off-by: joshvanl <me@joshvanl.dev> * go mod tidy Signed-off-by: joshvanl <me@joshvanl.dev> * Fix race condition in scheduler watch job tests Signed-off-by: joshvanl <me@joshvanl.dev> --------- Signed-off-by: joshvanl <me@joshvanl.dev>
- Loading branch information
Showing
32 changed files
with
1,112 additions
and
112 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
18 changes: 18 additions & 0 deletions
18
tests/integration/suite/actors/reminders/failurepolicy/failurepolicy.go
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,18 @@ | ||
/* | ||
Copyright 2024 The Dapr Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package failurepolicy | ||
|
||
import ( | ||
_ "github.com/dapr/dapr/tests/integration/suite/actors/reminders/failurepolicy/noset" | ||
) |
79 changes: 79 additions & 0 deletions
79
tests/integration/suite/actors/reminders/failurepolicy/noset/allfail.go
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,79 @@ | ||
/* | ||
Copyright 2024 The Dapr Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package noset | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"path" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1" | ||
"github.com/dapr/dapr/tests/integration/framework" | ||
"github.com/dapr/dapr/tests/integration/framework/process/daprd/actors" | ||
"github.com/dapr/dapr/tests/integration/framework/process/scheduler" | ||
"github.com/dapr/dapr/tests/integration/suite" | ||
"github.com/dapr/kit/concurrency/slice" | ||
) | ||
|
||
func init() { | ||
suite.Register(new(allfail)) | ||
} | ||
|
||
type allfail struct { | ||
actors *actors.Actors | ||
triggered slice.Slice[string] | ||
} | ||
|
||
func (a *allfail) Setup(t *testing.T) []framework.Option { | ||
a.triggered = slice.String() | ||
|
||
scheduler := scheduler.New(t) | ||
a.actors = actors.New(t, | ||
actors.WithScheduler(scheduler), | ||
actors.WithFeatureSchedulerReminders(true), | ||
actors.WithActorTypes("helloworld"), | ||
actors.WithActorTypeHandler("helloworld", func(w http.ResponseWriter, req *http.Request) { | ||
a.triggered.Append(path.Base(req.URL.Path)) | ||
w.WriteHeader(http.StatusInternalServerError) | ||
}), | ||
) | ||
|
||
return []framework.Option{ | ||
framework.WithProcesses(scheduler, a.actors), | ||
} | ||
} | ||
|
||
func (a *allfail) Run(t *testing.T, ctx context.Context) { | ||
a.actors.WaitUntilRunning(t, ctx) | ||
|
||
_, err := a.actors.GRPCClient(t, ctx).RegisterActorReminder(ctx, &rtv1.RegisterActorReminderRequest{ | ||
ActorType: "helloworld", | ||
ActorId: "1234", | ||
Name: "test", | ||
DueTime: "0s", | ||
}) | ||
require.NoError(t, err) | ||
|
||
assert.EventuallyWithT(t, func(c *assert.CollectT) { | ||
assert.ElementsMatch(c, []string{"test", "test", "test", "test"}, a.triggered.Slice()) | ||
}, time.Second*10, time.Millisecond*10) | ||
|
||
time.Sleep(time.Second * 2) | ||
assert.ElementsMatch(t, []string{"test", "test", "test", "test"}, a.triggered.Slice()) | ||
} |
90 changes: 90 additions & 0 deletions
90
tests/integration/suite/actors/reminders/failurepolicy/noset/failfirst.go
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,90 @@ | ||
/* | ||
Copyright 2024 The Dapr Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package noset | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"path" | ||
"sync/atomic" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
rtv1 "github.com/dapr/dapr/pkg/proto/runtime/v1" | ||
"github.com/dapr/dapr/tests/integration/framework" | ||
"github.com/dapr/dapr/tests/integration/framework/process/daprd/actors" | ||
"github.com/dapr/dapr/tests/integration/framework/process/scheduler" | ||
"github.com/dapr/dapr/tests/integration/suite" | ||
"github.com/dapr/kit/concurrency/slice" | ||
) | ||
|
||
func init() { | ||
suite.Register(new(failfirst)) | ||
} | ||
|
||
type failfirst struct { | ||
actors *actors.Actors | ||
triggered slice.Slice[string] | ||
respErr atomic.Bool | ||
} | ||
|
||
func (f *failfirst) Setup(t *testing.T) []framework.Option { | ||
f.triggered = slice.String() | ||
f.respErr.Store(true) | ||
|
||
scheduler := scheduler.New(t) | ||
f.actors = actors.New(t, | ||
actors.WithScheduler(scheduler), | ||
actors.WithFeatureSchedulerReminders(true), | ||
actors.WithActorTypes("helloworld"), | ||
actors.WithActorTypeHandler("helloworld", func(w http.ResponseWriter, req *http.Request) { | ||
defer f.triggered.Append(path.Base(req.URL.Path)) | ||
if f.respErr.Load() { | ||
w.WriteHeader(http.StatusInternalServerError) | ||
} | ||
}), | ||
) | ||
|
||
return []framework.Option{ | ||
framework.WithProcesses(scheduler, f.actors), | ||
} | ||
} | ||
|
||
func (f *failfirst) Run(t *testing.T, ctx context.Context) { | ||
f.actors.WaitUntilRunning(t, ctx) | ||
|
||
_, err := f.actors.GRPCClient(t, ctx).RegisterActorReminder(ctx, &rtv1.RegisterActorReminderRequest{ | ||
ActorType: "helloworld", | ||
ActorId: "1234", | ||
Name: "test", | ||
DueTime: "0s", | ||
}) | ||
require.NoError(t, err) | ||
|
||
assert.EventuallyWithT(t, func(c *assert.CollectT) { | ||
assert.ElementsMatch(c, []string{"test"}, f.triggered.Slice()) | ||
}, time.Second*10, time.Millisecond*10) | ||
|
||
f.respErr.Store(false) | ||
|
||
assert.EventuallyWithT(t, func(c *assert.CollectT) { | ||
assert.ElementsMatch(c, []string{"test", "test"}, f.triggered.Slice()) | ||
}, time.Second*10, time.Millisecond*10) | ||
|
||
time.Sleep(time.Second * 2) | ||
assert.ElementsMatch(t, []string{"test", "test"}, f.triggered.Slice()) | ||
} |
Oops, something went wrong.