8000 Run e2e tests against the current UI code via Temporal CLI by robholland · Pull Request #1010 · temporalio/ui · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Run e2e tests against the current UI code via Temporal CLI #1010

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

Merged
merged 8 commits into from
Jan 5, 2023
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
53 changes: 53 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: End To End Integration Tests

on:
push:
# branches: [main]
branches: [rh-integration]
# pull_request:
# branches: [rh-integration]

jobs:
e2e-integration:
runs-on: ubuntu-latest
steps:
- name: Checkout Server
uses: actions/checkout@v2
with:
repository: temporalio/ui-server
ref: main
- uses: actions/setup-go@v3
with:
go-version-file: "go.mod"
- uses: actions/setup-node@v1
with:
node-version: 16
- uses: pnpm/action-setup@v2.2.2
with:
version: 7
- name: Checkout UI
uses: actions/checkout@v2
with:
path: ui
- name: Re-build UI
run: |
make install-ui build-ui
- name: Checkout CLI
uses: actions/checkout@v2
with:
repository: temporalio/cli
path: cli
- name: Build CLI
run: |
cd cli && go mod edit -replace github.com/temporalio/ui-server/v2=../ && go build -o ../temporal-cli ./cmd/temporal
- name: Run Playwright Tests
run: |
./temporal-cli server start-dev --ui-codec-endpoint http://localhost:8234 &
cd ui/e2e
go run worker/main.go &
go run starter/main.go
go run ./codec-server -port 8234 -web http://localhost:8233 &
export E2E_UI_ADDRESS=http://localhost:8233
pnpm install
npx playwright install chromium --with-deps
npx playwright test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ node_modules
/.vercel_build_output
/.vercel
/.histoire/*
/build-local
1 change: 1 addition & 0 deletions e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
playwright-report/
6 changes: 6 additions & 0 deletions e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# ui server E2E tests

[![E2E Tests](https://github.com/temporalio/ui-server/actions/workflows/e2e.yml/badge.svg)](https://github.com/temporalio/ui-server/actions/workflows/e2e.yml)

E2E specifies a set of tests that run against a real Temporal server

109 changes: 109 additions & 0 deletions e2e/codec-server/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package main

import (
"flag"
"fmt"
"net/http"
"os"
"os/signal"
"strconv"

"github.com/temporalio/ui/e2e"

"go.temporal.io/sdk/converter"
"go.temporal.io/server/common/log"
"go.temporal.io/server/common/log/tag"
)

var logger log.Logger

// newCORSHTTPHandler wraps a HTTP handler with CORS support
func newCORSHTTPHandler(web string, next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", web)
w.Header().Set("Access-Control-Allow-Credentials", "true")
w.Header().Set("Access-Control-Allow-Headers", "Authorization,Content-Type,X-Namespace")

if r.Method == "OPTION 8000 S" {
return
}

next.ServeHTTP(w, r)
})
}

// HTTP handler for codecs.
// This remote codec server example supports URLs like: /{namespace}/encode and /{namespace}/decode
// For example, for the default namespace you would hit /default/encode and /default/decode
// It will also accept URLs: /encode and /decode with the X-Namespace set to indicate the namespace.
func newPayloadCodecNamespacesHTTPHandler(encoders map[string][]converter.PayloadCodec) http.Handler {
mux := http.NewServeMux()

codecHandlers := make(map[string]http.Handler, len(encoders))
for namespace, codecChain := range encoders {
fmt.Printf("Handling namespace: %s\n", namespace)

handler := converter.NewPayloadCodecHTTPHandler(codecChain...)
mux.Handle("/"+namespace+"/", handler)

codecHandlers[namespace] = handler
}

mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
namespace := r.Header.Get("X-Namespace")
if namespace != "" {
if handler, ok := codecHandlers[namespace]; ok {
handler.ServeHTTP(w, r)
return
}
}
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
}))

return mux
}

var portFlag int
var webFlag string

func init() {
logger = log.NewCLILogger()

flag.IntVar(&portFlag, "port", 8081, "Port to listen on")
flag.StringVar(&webFlag, "web", "", "Temporal Web URL. Optional: enables CORS which is required for access from Temporal Web")
}

func main() {
flag.Parse()

// Set codecs per namespace here.
// Only handle codecs for the default namespace in this example.
codecs := map[string][]converter.PayloadCodec{
"default": {e2e.NewPayloadCodec()},
}

handler := newPayloadCodecNamespacesHTTPHandler(codecs)

if webFlag != "" {
fmt.Printf("CORS enabled for Origin: %s\n", webFlag)
handler = newCORSHTTPHandler(webFlag, handler)
}

srv := &http.Server{
Addr: "0.0.0.0:" + strconv.Itoa(portFlag),
Handler: handler,
}

errCh := make(chan error, 1)
go func() { errCh <- srv.ListenAndServe() }()

sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt)

select {
case <-sigCh:
_ = srv.Close()
case err := <-errCh:
logger.Fatal("error", tag.NewErrorTag(err))
}
}
67 changes: 67 additions & 0 deletions e2e/data_converter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package e2e

import (
"github.com/golang/snappy"
commonpb "go.temporal.io/api/common/v1"
"go.temporal.io/sdk/converter"
)

var DataConverter = NewDataConverter(converter.GetDefaultDataConverter())

// NewDataConverter creates a new data converter that wraps the given data
// converter with snappy compression.
func NewDataConverter(underlying converter.DataConverter) converter.DataConverter {
return converter.NewCodecDataConverter(underlying, NewPayloadCodec())
}

func NewPayloadCodec() converter.PayloadCodec {
return &Codec{}
}

// Codec implements converter.PayloadEncoder for snappy compression.
type Codec struct{}

// Encode implements converter.PayloadCodec.Encode.
func (e *Codec) Encode(payloads []*commonpb.Payload) ([]*commonpb.Payload, error) {
result := make([]*commonpb.Payload, len(payloads))
for i, p := range payloads {
// Marshal proto
origBytes, err := p.Marshal()
if err != nil {
return payloads, err
}
// Compress
b := snappy.Encode(nil, origBytes)
result[i] = &commonpb.Payload{
Metadata: map[string][]byte{converter.MetadataEncoding: []byte("binary/snappy")},
Data: b,
}
}

return result, nil
}

// Decode implements converter.PayloadCodec.Decode.
func (*Codec) Decode(payloads []*commonpb.Payload) ([]*commonpb.Payload, error) {
result := make([]*commonpb.Payload, len(payloads))
for i, p := range payloads {
// Only if it's our encoding
if string(p.Metadata[converter.MetadataEncoding]) != "binary/snappy" {
result[i] = p
continue
}
// Uncompress
b, err := snappy.Decode(nil, p.Data)
if err != nil {
return payloads, err
}
// Unmarshal proto
result[i] = &commonpb.Payload{}
err = result[i].Unmarshal(b)
if err != nil {
return payloads, err
}
}

return result, nil
}
12 changes: 12 additions & 0 deletions e2e/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module github.com/temporalio/ui/e2e

go 1.16

require (
github.com/golang/snappy v0.0.4
github.com/google/uuid v1.3.0
go.temporal.io/api v1.13.0
go.temporal.io/sdk v1.19.0
go.temporal.io/server v1.15.2
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect
)
Loading
0