Skip to content

Commit

Permalink
Update test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkleeman committed Nov 8, 2024
1 parent d8408da commit 8e020ac
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
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
})
}

0 comments on commit 8e020ac

Please sign in to comment.