Files
Stephan BehnkeandGitHub 7a7b735f55 Revamp Update package's unit tests (1/2) (#6001)
## What changed?
<!-- Describe what has changed in this PR -->

- [x] move both stores (and their mocks) into own files
- [x] replace proto helpers with shared ones
- [x] rework Registry's Find() tests
- [x] rework Registry's HasOutgoingMessages() tests
- [x] rework Registry's FindOrCreate() tests
- [x] remove duplicate `TestStorageErrorWhenLookingUpCompletedOutcome`
(already part of `Find` tests)
- [x] remove duplicate `TestUpdateRemovalFromRegistry` (already part of
`FindOrCreate` tests)
- [x] rework Registry's Send() tests
- [x] rework Registry's RejectUnprocessed() tests
- [x] add test for Registry's FailoverVersion()
- [x] add test for Registry's NewRegistry() 
- [x] remove `TestUpdateAccepted_WorkflowCompleted` (already covered) 
- [x] add test for Registry's TryResurrect()

## Why?
<!-- Tell your future self why have you made these changes -->

To make sure the update package tests are in tip top shape.

## How did you test it?
<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->

All tests (and production code changes are purely cosmetic).

## Potential risks
<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->

## Documentation
<!-- Have you made sure this change doesn't falsify anything currently
stated in `docs/`? If significant
new behavior is added, have you described that in `docs/`? -->

## Is hotfix candidate?
<!-- Is this PR a hotfix candidate or does it require a notification to
be sent to the broader community? (Yes/No) -->
2024-05-28 20:27:00 +00:00

75 lines
2.9 KiB
Go

// The MIT License
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package update
import (
"context"
historypb "go.temporal.io/api/history/v1"
updatepb "go.temporal.io/api/update/v1"
persistencespb "go.temporal.io/server/api/persistence/v1"
"go.temporal.io/server/internal/effect"
)
type (
// UpdateStore represents the update package's requirements for reading updates from the store.
UpdateStore interface {
VisitUpdates(visitor func(updID string, updInfo *persistencespb.UpdateInfo))
GetUpdateOutcome(ctx context.Context, updateID string) (*updatepb.Outcome, error)
GetCurrentVersion() int64
IsWorkflowExecutionRunning() bool
}
// EventStore is the interface that an Update needs to read and write events
// and to be notified when buffered writes have been flushed. It is the
// expectation of this code that writes to EventStore will return before the
// data has been made durable. Callbacks attached to the EventStore via
// OnAfterCommit and OnAfterRollback *must* be called after the EventStore
// state is successfully written or is discarded.
EventStore interface {
effect.Controller
// AddWorkflowExecutionUpdateAcceptedEvent writes an update accepted
// event. The data may not be durable when this function returns.
AddWorkflowExecutionUpdateAcceptedEvent(
updateID string,
acceptedRequestMessageId string,
acceptedRequestSequencingEventId int64,
acceptedRequest *updatepb.Request,
) (*historypb.HistoryEvent, error)
// AddWorkflowExecutionUpdateCompletedEvent writes an update completed
// event. The data may not be durable when this function returns.
AddWorkflowExecutionUpdateCompletedEvent(
acceptedEventID int64,
resp *updatepb.Response,
) (*historypb.HistoryEvent, error)
// CanAddEvent returns true if an event can be added to the EventStore.
CanAddEvent() bool
}
)