Skip to content
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
121 changes: 115 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ permissions:
contents: read

jobs:
build:
dependencies:
name: Verify dependencies
runs-on: ubuntu-latest

steps:
Expand All @@ -20,14 +21,122 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v7
with:
go-version: "1.27.x"
go-version: '1.27.x'
check-latest: true
cache-dependency-path: |
go.sum
tools/go.sum

- name: Go version
run: go version
- name: Download modules
run: go mod download

- name: Verify
run: make verify
- name: Verify modules
run: go mod verify

generated:
name: Verify generated mocks
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v7

- name: Setup Go
uses: actions/setup-go@v7
with:
go-version: '1.27.x'
check-latest: true
cache-dependency-path: |
go.sum
tools/go.sum

- name: Verify generated mocks
run: make mockgen

lint:
name: Lint
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v7

- name: Setup Go
uses: actions/setup-go@v7
with:
go-version: '1.27.x'
check-latest: true
cache-dependency-path: |
go.sum
tools/go.sum

- name: Lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.15.0
args: --timeout=10m

vulncheck:
name: Check vulnerabilities
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v7

- name: Setup Go
uses: actions/setup-go@v7
with:
go-version: '1.27.x'
check-latest: true
cache-dependency-path: |
go.sum
tools/go.sum

- name: Check vulnerabilities
run: make vulncheck

test:
name: Test (${{ matrix.os }})
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- name: Checkout
uses: actions/checkout@v7

- name: Setup Go
uses: actions/setup-go@v7
with:
go-version: '1.27.x'
check-latest: true
cache-dependency-path: |
go.sum
tools/go.sum

- name: Test
run: go test ./... -count=1 -timeout=600s

race:
name: Race detector
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v7

- name: Setup Go
uses: actions/setup-go@v7
with:
go-version: '1.27.x'
check-latest: true
cache-dependency-path: |
go.sum
tools/go.sum

- name: Race tests
run: go test -race ./... -count=1 -timeout=600s
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ROOT_PATH := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
COVERAGE_PATH := $(ROOT_PATH).coverage/
MOCK_GENERATED_PATHS := mock/ ':(glob)**/mock_*_test.go'

# Use the locally installed Go toolchain.
export GOTOOLCHAIN=local
Expand All @@ -14,10 +15,12 @@ mockgen: install-mockgen
@echo "Generating mocks..."
@rm -rf mock
@mkdir -p mock
$(MOCKGEN) -destination=mock/Repository.go -package=mock github.com/e2engine/core/repository EntityRepository,ResourceRepository,TestRepository,TestExecutionRepository,TestSuiteExecutionRepository
$(MOCKGEN) -destination=mock/Runtime.go -package=mock github.com/e2engine/core/execute/runtime Service,ServiceProvider,Router,RouterProvider
$(MOCKGEN) -destination=mock/Execute.go -package=mock github.com/e2engine/core/execute ProtocolExecutor
$(MOCKGEN_LINK) -destination=mock/Repository.go -package=mock github.com/e2engine/core/repository EntityRepository,ResourceRepository,TestRepository,TestExecutionRepository,TestSuiteExecutionRepository
$(MOCKGEN_LINK) -destination=mock/Runtime.go -package=mock github.com/e2engine/core/execute/runtime Service,ServiceProvider,Router,RouterProvider
$(MOCKGEN_LINK) -destination=mock/Execute.go -package=mock github.com/e2engine/core/execute ProtocolExecutor
go generate ./...
@git diff HEAD --exit-code -- $(MOCK_GENERATED_PATHS)
@test -z "$$(git ls-files --others --exclude-standard -- $(MOCK_GENERATED_PATHS))"

.PHONY: lint
lint: install-golangci-lint
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

Core domain model, execution logic, and public APIs for E2Engine.

This module provides the shared models and execution components used across E2Engine, including test and environment definitions, test execution, runtime service management, scheduling, persistence interfaces, and transport primitives.

Part of [E2Engine](https://e2engine.dev), an open-source platform for declarative end-to-end testing.

E2Engine project on GitHub: [E2Engine on GitHub](https://github.com/e2engine).
This module provides the shared models and execution components used across E2Engine, including test and environment definitions, test execution, runtime service management, scheduling, persistence interfaces, and transport primitives.

## Installation

Expand Down Expand Up @@ -66,6 +64,12 @@ Run the complete verification suite:
make verify
```

## Links

- [E2Engine website](https://e2engine.dev)
- [E2Engine documentation](https://e2engine.dev/docs)
- [E2Engine on GitHub](https://github.com/e2engine)

## License

Licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE).
4 changes: 1 addition & 3 deletions api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ func WithRuntimeConfig(config *runtimeconfig.Config) Option {
func getSettings(opts ...Option) (*settings, error) {
logger, err := log.NewSilentLogger()
if err != nil {
return nil, errorc.With(
errors.ErrCannotInitializeLogger, errorc.Error(keys.Cause, err),
)
return nil, errorc.WithCause(errors.ErrCannotInitializeLogger, err)
}

s := &settings{
Expand Down
5 changes: 1 addition & 4 deletions execute/runtime/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,7 @@ func (e *Environment) Mount(ctx context.Context) error {
}

if err := e.router.Mount(ctx); err != nil {
rErr := errorc.With(
errors.ErrFailedToMountRouter,
errorc.Error(keys.Cause, err),
)
rErr := errorc.WithCause(errors.ErrFailedToMountRouter, err)
return nativeerrors.Join(rErr, e.cleanupRouterAndServices(len(e.services)-1))
}

Expand Down
8 changes: 7 additions & 1 deletion execute/runtime/router/grpc/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (r *Router) Mount(ctx context.Context) error {

go func() {
err := server.Serve(listener)
if err != nil {
if err != nil && !nativeerrors.Is(err, grpcpkg.ErrServerStopped) {
r.logger.Error(
"Environment gRPC router listener stopped unexpectedly",
log.String(
Expand Down Expand Up @@ -423,6 +423,12 @@ func (r *Router) unmountMountedRoutes(
case <-done:
}

// Stop may run before Serve registers the listener.
if err := route.listener.Close(); err != nil &&
!nativeerrors.Is(err, net.ErrClosed) {
accErr = nativeerrors.Join(accErr, err)
}

if err := route.connection.Close(); err != nil {
r.logger.Error(
"Failed to close gRPC router connection",
Expand Down
17 changes: 11 additions & 6 deletions execute/runtime/router/grpc/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ func TestRouterUnmountCancelledContext(t *testing.T) {
t.Fatalf("Mount() error = %v", err)
}

address := router.mounted[0].listener.Addr().String()
listener := router.mounted[0].listener

ctx, cancel := context.WithCancel(context.Background())
cancel()
Expand All @@ -808,15 +808,20 @@ func TestRouterUnmountCancelledContext(t *testing.T) {
t.Fatal("expected mounted routes to be cleared")
}

connection, err := net.DialTimeout(
"tcp",
address,
time.Second,
)
if err := listener.(*net.TCPListener).SetDeadline(
time.Now().Add(time.Second),
); err != nil && !errors.Is(err, net.ErrClosed) {
t.Fatalf("SetDeadline() error = %v", err)
}

connection, err := listener.Accept()
if err == nil {
_ = connection.Close()
t.Fatal("listener still accepts connections after unmount")
}
if !errors.Is(err, net.ErrClosed) {
t.Fatalf("Accept() error = %v, want net.ErrClosed", err)
}
}

func TestRouterMultipleRoutes(t *testing.T) {
Expand Down
13 changes: 11 additions & 2 deletions execute/runtime/router/http/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ func TestRouterUnmountCancelledContext(t *testing.T) {
t.Fatalf("Mount() error = %v", err)
}

address := router.mounted[0].listener.Addr().String()
listener := router.mounted[0].listener

ctx, cancel := context.WithCancel(context.Background())
cancel()
Expand All @@ -492,11 +492,20 @@ func TestRouterUnmountCancelledContext(t *testing.T) {
t.Fatal("expected mounted routes to be cleared")
}

conn, err := net.DialTimeout("tcp", address, time.Second)
if err := listener.(*net.TCPListener).SetDeadline(
time.Now().Add(time.Second),
); err != nil && !errors.Is(err, net.ErrClosed) {
t.Fatalf("SetDeadline() error = %v", err)
}

conn, err := listener.Accept()
if err == nil {
_ = conn.Close()
t.Fatal("listener still accepts connections after unmount")
}
if !errors.Is(err, net.ErrClosed) {
t.Fatalf("Accept() error = %v, want net.ErrClosed", err)
}
}

func TestRouterMultipleRoutes(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions execute/runtime/service/grpc/methodresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/e2engine/core/model"
"github.com/e2engine/core/pkg/errors"
"github.com/e2engine/core/pkg/keys"
"github.com/e2engine/core/util"
"github.com/e2engine/core/util/fs"
)

type DescriptorLoader interface {
Expand Down Expand Up @@ -135,7 +135,7 @@ func (r *ProtoMethodResolver) loadFile(
)
}

if errValidate := util.ValidateFilePath(absolutePath); errValidate != nil {
if errValidate := fs.ValidateFilePath(absolutePath); errValidate != nil {
return nil, errorc.With(
errors.ErrInaccessiblePath,
errorc.String(keys.FilePath, path),
Expand All @@ -156,7 +156,7 @@ func (r *ProtoMethodResolver) loadFile(
Resolver: protocompile.WithStandardImports(
&protocompile.SourceResolver{
Accessor: func(name string) (io.ReadCloser, error) {
data, errRead := util.ReadFileWithinRoot(root, name)
data, errRead := fs.ReadFileWithinRoot(root, name)
if errRead != nil {
return nil, errRead
}
Expand Down
6 changes: 3 additions & 3 deletions execute/runtime/service/grpc/methodresolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/e2engine/core/model"
"github.com/e2engine/core/pkg/errors"
"github.com/e2engine/core/util"
"github.com/e2engine/core/util/fs"
)

func TestProtoMethodResolverResolveExternalModule(t *testing.T) {
Expand Down Expand Up @@ -935,7 +935,7 @@ message Secret {}
defer file.Close()

if err := file.Truncate(
util.MaxFileSize + 1,
fs.MaxFileSize + 1,
); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1014,7 +1014,7 @@ func TestProtoMethodResolverResolveExternalFileTooLarge(t *testing.T) {
t.Fatal(err)
}

if err := file.Truncate(util.MaxFileSize + 1); err != nil {
if err := file.Truncate(fs.MaxFileSize + 1); err != nil {
_ = file.Close()
t.Fatal(err)
}
Expand Down
5 changes: 1 addition & 4 deletions execute/worker/grpc/evaluate.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,7 @@ func (e *Evaluator) Matches(
actual.GRPC.Request.Message,
actualMessage,
); err != nil {
return false, errorc.With(
ErrCannotDecodeCapturedRequest,
errorc.Error(keys.Cause, err),
)
return false, errorc.WithCause(ErrCannotDecodeCapturedRequest, err)
}

return match.IsGRPCMessageMatched(
Expand Down
6 changes: 1 addition & 5 deletions execute/worker/grpc/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
servicegrpc "github.com/e2engine/core/execute/runtime/service/grpc"
"github.com/e2engine/core/model"
"github.com/e2engine/core/pkg/errors"
"github.com/e2engine/core/pkg/keys"
)

type TestExecutor struct {
Expand Down Expand Up @@ -82,10 +81,7 @@ func (e *TestExecutor) Execute(
spec.Message,
request,
); errUnmarshal != nil {
return errorc.With(
errors.ErrCannotBuildGRPCRequest,
errorc.Error(keys.Cause, errUnmarshal),
)
return errorc.WithCause(errors.ErrCannotBuildGRPCRequest, errUnmarshal)
}

if proto.Size(request) > e.cfg.MaxMessageSize {
Expand Down
Loading
Loading