Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CAPPL-411] do not fail when deleting non existing workflow spec #15768

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
9 changes: 8 additions & 1 deletion core/services/workflows/syncer/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package syncer
import (
"bytes"
"context"
"database/sql"
"encoding/base64"
"encoding/hex"
"encoding/json"
Expand Down Expand Up @@ -642,9 +643,15 @@ func (h *eventHandler) workflowDeletedEvent(
return err
}

if err := h.orm.DeleteWorkflowSpec(ctx, hex.EncodeToString(payload.WorkflowOwner), payload.WorkflowName); err != nil {
err := h.orm.DeleteWorkflowSpec(ctx, hex.EncodeToString(payload.WorkflowOwner), payload.WorkflowName)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
h.lggr.Warnw("workflow spec not found", "workflowID", hex.EncodeToString(payload.WorkflowID[:]))
return nil
}
return fmt.Errorf("failed to delete workflow spec: %w", err)
}

return nil
}

Expand Down
55 changes: 55 additions & 0 deletions core/services/workflows/syncer/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,61 @@ func Test_workflowDeletedHandler(t *testing.T) {
_, err = h.engineRegistry.Get(wfIDs)
require.Error(t, err)
})
t.Run("success deleting non-existing workflow spec", func(t *testing.T) {
var (
ctx = testutils.Context(t)
lggr = logger.TestLogger(t)
db = pgtest.NewSqlxDB(t)
orm = NewWorkflowRegistryDS(db, lggr)
emitter = custmsg.NewLabeler()

binary = wasmtest.CreateTestBinary(binaryCmd, binaryLocation, true, t)
encodedBinary = []byte(base64.StdEncoding.EncodeToString(binary))
config = []byte("")
secretsURL = "http://example.com"
binaryURL = "http://example.com/binary"
configURL = "http://example.com/config"
wfOwner = []byte("0xOwner")

fetcher = newMockFetcher(map[string]mockFetchResp{
binaryURL: {Body: encodedBinary, Err: nil},
configURL: {Body: config, Err: nil},
secretsURL: {Body: []byte("secrets"), Err: nil},
})
)

giveWFID, err := pkgworkflows.GenerateWorkflowID(wfOwner, "workflow-name", binary, config, secretsURL)
require.NoError(t, err)

er := NewEngineRegistry()
store := wfstore.NewDBStore(db, lggr, clockwork.NewFakeClock())
registry := capabilities.NewRegistry(lggr)
registry.SetLocalRegistry(&capabilities.TestMetadataRegistry{})
h := NewEventHandler(
lggr,
orm,
fetcher,
store,
registry,
emitter,
clockwork.NewFakeClock(),
workflowkey.Key{},
WithEngineRegistry(er),
)

deleteEvent := WorkflowRegistryWorkflowDeletedV1{
WorkflowID: giveWFID,
WorkflowOwner: wfOwner,
WorkflowName: "workflow-name",
DonID: 1,
}
err = h.workflowDeletedEvent(ctx, deleteEvent)
require.NoError(t, err)

// Verify the record is deleted in the database
_, err = orm.GetWorkflowSpec(ctx, hex.EncodeToString(wfOwner), "workflow-name")
require.Error(t, err)
})
}

func Test_workflowPausedActivatedUpdatedHandler(t *testing.T) {
Expand Down
Loading