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

Update test suite #44

Merged
merged 1 commit into from
Nov 8, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
name: "Features integration test (sdk-test-suite version ${{ matrix.sdk-test-suite }})"
strategy:
matrix:
sdk-test-suite: [ "1.6" ]
sdk-test-suite: [ "2.1" ]
permissions:
contents: read
issues: read
Expand Down
6 changes: 3 additions & 3 deletions test-services/exclusions.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exclusions:
"default": []
"alwaysSuspending": []
"singleThreadSinglePartition": []
"default": ["RunRetry"]
"alwaysSuspending": ["RunRetry"]
"singleThreadSinglePartition": ["RunRetry"]
59 changes: 58 additions & 1 deletion test-services/testutils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"os"
"strings"
"sync/atomic"
"time"
Expand All @@ -21,6 +22,17 @@ type CreateAwakeableAndAwaitItResponse struct {
Value *string `json:"value,omitempty"`
}

type InterpretRequest struct {
ListName string `json:"listName"`
Commands []Command `json:"commands"`
}

type Command struct {
Type string `json:"type"`
AwakeableKey string `json:"awakeableKey"`
EnvName string `json:"envName"`
}

func init() {
REGISTRY.AddDefinition(
restate.NewService("TestUtilsService").
Expand All @@ -36,6 +48,10 @@ func init() {
func(ctx restate.Context, _ restate.Void) (map[string]string, error) {
return ctx.Request().Headers, nil
})).
Handler("rawEcho", restate.NewServiceHandler(
func(ctx restate.Context, input []byte) ([]byte, error) {
return input, nil
}, restate.WithBinary)).
Handler("createAwakeableAndAwaitIt", restate.NewServiceHandler(
func(ctx restate.Context, req CreateAwakeableAndAwaitItRequest) (CreateAwakeableAndAwaitItResponse, error) {
awakeable := restate.Awakeable[string](ctx)
Expand Down Expand Up @@ -95,5 +111,46 @@ func init() {
})
}
return invokedSideEffects.Load(), nil
})))
})).
Handler("getEnvVariable", restate.NewServiceHandler(
func(ctx restate.Context, env string) (string, error) {
return restate.Run(ctx, func(ctx restate.RunContext) (string, error) {
return os.Getenv(env), nil
})
})).
Handler("interpretCommands", restate.NewServiceHandler(
func(ctx restate.Context, req InterpretRequest) (restate.Void, error) {
for _, command := range req.Commands {
switch command.Type {
case "createAwakeableAndAwaitIt":
result, err := createAwakeableAndAwaitIt(ctx, command.AwakeableKey)
if err != nil {
return restate.Void{}, err
}
restate.ObjectSend(ctx, "ListObject", req.ListName, "append").Send(result)
case "getEnvVariable":
result, err := getEnvVariable(ctx, command.EnvName)
if err != nil {
return restate.Void{}, err
}
restate.ObjectSend(ctx, "ListObject", req.ListName, "append").Send(result)
}
}
return restate.Void{}, nil
})),
)
}

func createAwakeableAndAwaitIt(ctx restate.Context, awakeableKey string) (string, error) {
awakeable := restate.Awakeable[string](ctx)
if _, err := restate.Object[restate.Void](ctx, "AwakeableHolder", awakeableKey, "hold").Request(awakeable.Id()); err != nil {
return "", err
}
return awakeable.Result()
}

func getEnvVariable(ctx restate.Context, envName string) (string, error) {
return restate.Run(ctx, func(ctx restate.RunContext) (string, error) {
return os.Getenv(envName), nil
})
}
Loading