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

feat: chaos abort #3733

Merged
merged 3 commits into from
Sep 10, 2020
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
22 changes: 22 additions & 0 deletions conformance/chaos/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ const (
// MethodMutateState is the identifier for the method that attempts to mutate
// a state value in the actor.
MethodMutateState
// MethodAbortWith is the identifier for the method that panics optionally with
// a passed exit code.
MethodAbortWith
)

// Exports defines the methods this actor exposes publicly.
Expand All @@ -74,6 +77,7 @@ func (a Actor) Exports() []interface{} {
MethodDeleteActor: a.DeleteActor,
MethodSend: a.Send,
MethodMutateState: a.MutateState,
MethodAbortWith: a.AbortWith,
}
}

Expand Down Expand Up @@ -230,3 +234,21 @@ func (a Actor) MutateState(rt runtime.Runtime, args *MutateStateArgs) *adt.Empty
}
return nil
}

// AbortWithArgs are the arguments to the Actor.AbortWith method, specifying the
// exit code to (optionally) abort with and the message.
type AbortWithArgs struct {
Code exitcode.ExitCode
Message string
Uncontrolled bool
}

// AbortWith simply causes a panic with the passed exit code.
func (a Actor) AbortWith(rt runtime.Runtime, args *AbortWithArgs) *adt.EmptyValue {
if args.Uncontrolled { // uncontrolled abort: directly panic
panic(args.Message)
} else {
rt.Abortf(args.Code, args.Message)
}
return nil
}
116 changes: 116 additions & 0 deletions conformance/chaos/cbor_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions conformance/chaos/gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func main() {
chaos.SendArgs{},
chaos.SendReturn{},
chaos.MutateStateArgs{},
chaos.AbortWithArgs{},
); err != nil {
panic(err)
}
Expand Down