Skip to content
Draft
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
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,47 @@ history checks are performed:
Currently there are not ways for features to opt out of specific history checks. To opt out of all history checking for
a specific run, use `--no-history-check`.

## Cross-language features

A feature with `"crossLanguage": true` in its `config.json` has a conventional
`driver/` Go program and ordinary `feature.<language>` participants. Run these
features with their own subcommand:

```sh
go run . run-cross-language tracing/encoded_headers
```

The runner discovers participants from the files, prepares each participating SDK
once, and supplies the driver with prepared harness commands, a server, namespace,
and unique task-queue prefix through `FEATURE_CROSS_LANGUAGE`. The
`harness/go/crosslanguage` package reads this manifest and invokes harnesses in
`client` or `worker` roles. Workers announce readiness before clients are run.
The driver chooses scenarios, pairs, and assertions; the runner does not generate
a language matrix. A nonzero driver exit fails the feature in the normal summary.

Use repeated `--sdk-version language=version-or-local-checkout` options to select
SDKs independently. For example:

```sh
go run . run-cross-language --sdk-version cs=1.22.0 --sdk-version ts=/path/to/sdk-typescript tracing/encoded_headers
```

Use repeated `--sdk-language` options to prepare only selected participants, without
imposing pair policy on the runner. For the focused original regression:

```sh
ENCODED_HEADERS_PAIRS=cs:ts go run . run-cross-language --sdk-language cs --sdk-language ts --sdk-version cs=1.22.0 --sdk-version ts=/path/to/sdk-typescript tracing/encoded_headers
```

Go, Java, Python, Ruby, Rust, .NET and TypeScript harnesses expose separate roles.
See the feature's README for which roles its participants support and its
feature-specific scenario filters. Cross-language features own their
history assertions and do not use the single-language history comparison/generation
mechanism. This subcommand exposes SDK selection, server/namespace/TLS options,
and temporary-build retention, but not history-generation or prepared-directory flags.
The existing `run` and `prepare` subcommands continue to require `--lang` and select
only single-language features.

## Writing Features

Developers can write workflows and activities that represent a SDK "feature". These are organized into directories under
Expand Down
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ dependencies {
implementation 'com.jayway.jsonpath:json-path:2.6.0'
implementation 'info.picocli:picocli:4.6.2'
implementation 'io.temporal:temporal-sdk:latest.release'
implementation 'io.temporal:temporal-opentracing:latest.release'
implementation 'io.opentelemetry:opentelemetry-sdk:1.49.0'
implementation 'io.opentelemetry:opentelemetry-opentracing-shim:1.49.0'
implementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
implementation 'org.reflections:reflections:0.10.2'
}
Expand Down
1 change: 1 addition & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func NewApp() *cli.App {
Commands: []*cli.Command{
prepareCmd(),
runCmd(),
runCrossLanguageCmd(),
buildImageCmd(),
publishImageCmd(),
latestSdkVersionCmd(),
Expand Down
7 changes: 4 additions & 3 deletions cmd/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ func prepareCmd() *cli.Command {

// PrepareConfig is configuration for NewPreparer.
type PrepareConfig struct {
DirName string
Lang string
Version string
DirName string
Lang string
Version string
crossLanguage bool
}

func (p *PrepareConfig) flags() []cli.Flag {
Expand Down
21 changes: 18 additions & 3 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,13 @@ type Runner struct {
log log.Logger
config RunConfig
// Root of the features repo
rootDir string
createTime time.Time
program sdkbuild.Program
rootDir string
createTime time.Time
program sdkbuild.Program
crossPrograms map[string]sdkbuild.Program
crossLanguage bool
crossVersions map[string]string
crossLanguages []string
}

type runBatch struct {
Expand Down Expand Up @@ -366,6 +370,10 @@ func (r *Runner) Run(ctx context.Context, patterns []string) error {
}
}
}
return r.runFeatures(ctx, features, patterns)
}

func (r *Runner) runFeatures(ctx context.Context, features []*RunFeature, patterns []string) error {
features = r.filterFeaturesForExternalServer(features, patterns)
if len(features) == 0 {
return fmt.Errorf("no features matched")
Expand Down Expand Up @@ -481,6 +489,10 @@ func (r *Runner) runBatch(ctx context.Context, batch runBatch) error {
defer proxyServer.Close()
}

if r.crossLanguage {
return r.runCrossLanguageBatch(ctx, config, batch)
}

l, err := net.Listen("tcp", summaryListenAddr)
if err != nil {
return err
Expand Down Expand Up @@ -959,6 +971,9 @@ func (r *Runner) destroyTempDir() {
if r.program != nil {
_ = os.RemoveAll(r.program.Dir())
}
for _, program := range r.crossPrograms {
_ = os.RemoveAll(program.Dir())
}
}

func normalizeLangName(lang string) (string, error) {
Expand Down
225 changes: 225 additions & 0 deletions cmd/run_cross_language.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
package cmd

import (
"context"
"encoding/json"
"fmt"
"os"
"os/exec"
"path/filepath"
"slices"
"strings"
"time"

hcmd "github.com/temporalio/features/harness/go/cmd"
"github.com/temporalio/features/harness/go/crosslanguage"
"github.com/temporalio/features/sdkbuild"
"github.com/urfave/cli/v2"
)

type CrossLanguageRunConfig struct {
RunConfig
SDKVersions cli.StringSlice
SDKLanguages cli.StringSlice
}

func runCrossLanguageCmd() *cli.Command {
var config CrossLanguageRunConfig
return &cli.Command{
Name: "run-cross-language",
Usage: "Run crossLanguage features using their custom drivers",
Flags: append([]cli.Flag{
&cli.StringSliceFlag{
Name: "sdk-version", Destination: &config.SDKVersions,
Usage: "SDK selection, e.g. cs=1.22.0 or ts=/path/to/sdk",
},
&cli.StringSliceFlag{
Name: "sdk-language", Destination: &config.SDKLanguages,
Usage: "Prepare only these participants (repeatable; default: all discovered languages)",
},
&cli.BoolFlag{
Name: "retain-temp-dir", Destination: &config.RetainTempDir,
Usage: "Do not delete temporary SDK and driver builds",
},
}, config.dockerRunFlags()...),
Action: func(ctx *cli.Context) error {
versions, err := config.sdkVersions()
if err != nil {
return err
}
runner := NewRunner(config.RunConfig)
runner.crossLanguage, runner.crossVersions = true, versions
for _, language := range config.SDKLanguages.Value() {
lang, err := normalizeLangName(language)
if err != nil {
return err
}
runner.crossLanguages = append(runner.crossLanguages, lang)
}
features, err := runner.GlobCrossLanguageFeatures(ctx.Args().Slice())
if err != nil {
return err
}
return runner.runFeatures(ctx.Context, features, ctx.Args().Slice())
},
}
}

func (config CrossLanguageRunConfig) sdkVersions() (map[string]string, error) {
versions := map[string]string{}
for _, selection := range config.SDKVersions.Value() {
lang, version, ok := strings.Cut(selection, "=")
lang, err := normalizeLangName(lang)
if !ok || err != nil || version == "" {
return nil, fmt.Errorf("invalid --sdk-version %q: expected language=version-or-path", selection)
}
if _, exists := versions[lang]; exists {
return nil, fmt.Errorf("duplicate --sdk-version for %s", lang)
}
versions[lang] = version
}
return versions, nil
}

func (r *Runner) runCrossLanguageBatch(ctx context.Context, config RunConfig, batch runBatch) error {
restoreEnv := setNamespaceCapabilitiesEnv(config.NamespaceCapabilitiesJSON)
defer restoreEnv()
var summary Summary
var failed bool
for _, feature := range batch.Run.Features {
err := r.runCrossLanguageFeature(ctx, config, feature, r.crossVersions)
entry := SummaryEntry{Name: feature.SummaryName(), Outcome: FeaturePassed}
if err != nil {
entry.Outcome, entry.Message = "FAILED", err.Error()
failed = true
}
summary = append(summary, entry)
}
label := batch.VariantName
if label == "" {
label = "default"
}
r.logFeatureSummary(label, summary)
if failed {
return fmt.Errorf("cross-language feature failed")
}
return nil
}

func (r *Runner) runCrossLanguageFeature(
ctx context.Context, config RunConfig, feature hcmd.RunFeature, versions map[string]string,
) error {
ctx, cancel := context.WithTimeout(ctx, 10*time.Minute)
defer cancel()
dir := filepath.Join(r.rootDir, "features", filepath.FromSlash(feature.Dir))
files, err := filepath.Glob(filepath.Join(dir, "feature.*"))
if err != nil {
return err
}
manifest := crosslanguage.Manifest{
Feature: feature.Dir, TaskQueue: feature.TaskQueue,
Programs: map[string]crosslanguage.Program{},
}
for _, file := range files {
lang := strings.TrimPrefix(filepath.Ext(file), ".")
if _, err := normalizeLangName(lang); err != nil {
continue
}
if len(r.crossLanguages) != 0 && !slices.Contains(r.crossLanguages, lang) {
continue
}
program, err := r.crossLanguageProgram(ctx, lang, versions[lang])
if err != nil {
return fmt.Errorf("prepare %s: %w", lang, err)
}
args := []string{"--server", config.Server, "--namespace", config.Namespace}
for _, option := range [][2]string{
{"--client-cert-path", config.ClientCertPath}, {"--client-key-path", config.ClientKeyPath},
{"--ca-cert-path", config.CACertPath}, {"--tls-server-name", config.TLSServerName},
{"--http-proxy-url", config.HTTPProxyURL},
} {
if option[1] != "" {
args = append(args, option[:]...)
}
}
if lang == "ts" {
args = append([]string{"./tslib/harness/ts/main.js"}, args...)
} else if lang == "go" {
args = append([]string{"run"}, args...)
} else if lang == "py" {
args = append([]string{"harness.python.main"}, args...)
}
command, err := program.NewCommand(ctx, args...)
if err != nil {
return err
}
manifest.Programs[lang] = crosslanguage.Program{Dir: command.Dir, Args: command.Args}
}
if len(manifest.Programs) == 0 {
return fmt.Errorf("%s has no feature.<language> participants", feature.Dir)
}
buildDir, err := os.MkdirTemp(r.rootDir, "program-cross-driver-")
if err != nil {
return err
}
if !config.RetainTempDir {
defer os.RemoveAll(buildDir)
}
binary := filepath.Join(buildDir, "driver")
build := exec.CommandContext(ctx, "go", "build", "-o", binary, ".")
build.Dir = filepath.Join(dir, "driver")
build.Stdout, build.Stderr = os.Stdout, os.Stderr
if err := build.Run(); err != nil {
return fmt.Errorf("build %s/driver: %w", feature.Dir, err)
}
data, err := json.Marshal(manifest)
if err != nil {
return err
}
command := exec.CommandContext(ctx, binary)
command.Dir = dir
command.Env = append(os.Environ(), crosslanguage.ManifestEnv+"="+string(data))
command.Stdout, command.Stderr = os.Stdout, os.Stderr
command.Cancel = func() error { return command.Process.Signal(os.Interrupt) }
command.WaitDelay = 10 * time.Second
if err := command.Run(); err != nil {
return fmt.Errorf("%s driver: %w", feature.Dir, err)
}
return nil
}

func (r *Runner) crossLanguageProgram(ctx context.Context, lang, version string) (sdkbuild.Program, error) {
if program := r.crossPrograms[lang]; program != nil {
return program, nil
}
p := NewPreparer(PrepareConfig{Lang: lang, Version: version, crossLanguage: true})
p.rootDir = r.rootDir
var program sdkbuild.Program
var err error
switch lang {
case "cs":
program, err = p.BuildDotNetProgram(ctx)
case "ts":
program, err = p.BuildTypeScriptProgram(ctx)
case "go":
program, err = p.BuildGoProgram(ctx)
case "py":
program, err = p.BuildPythonProgram(ctx)
case "java":
program, err = p.BuildJavaProgram(ctx, true)
case "rb":
program, err = p.BuildRubyProgram(ctx)
case "rs":
program, err = p.BuildRustProgram(ctx)
default:
return nil, fmt.Errorf("cross-language harness roles are not implemented for %s yet", lang)
}
if err != nil {
return nil, err
}
if r.crossPrograms == nil {
r.crossPrograms = map[string]sdkbuild.Program{}
}
r.crossPrograms[lang] = program
return program, nil
}
Loading
Loading