Skip to content

Commit

Permalink
feat: Add Echo App end-to-end test
Browse files Browse the repository at this point in the history
Update CHANGELOG.md

Co-authored-by: Victor Yves <torives@users.noreply.github.com>

Update CHANGELOG.md

Co-authored-by: Victor Yves <torives@users.noreply.github.com>

Update cmd/cartesi-rollups-cli/root/send/send.go

Co-authored-by: Gabriel de Quadros Ligneul <8294320+gligneul@users.noreply.github.com>

Update end-to-end-tests/client_util.go

Co-authored-by: Gabriel de Quadros Ligneul <8294320+gligneul@users.noreply.github.com>

Update end-to-end-tests/echo_test.go

Co-authored-by: Victor Yves <torives@users.noreply.github.com>

Update end-to-end-tests/client_util.go

Co-authored-by: Gabriel de Quadros Ligneul <8294320+gligneul@users.noreply.github.com>
  • Loading branch information
fmoura and gligneul committed Apr 10, 2024
1 parent 76d6b56 commit 2acaddc
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 96 deletions.
96 changes: 22 additions & 74 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,21 @@ permissions:
contents: write

jobs:
test:
e2etest:
runs-on: ubuntu-22.04
container:
image: debian:bookworm-20240311-slim
env:
RUSTFLAGS: -D warnings -C debuginfo=0
defaults:
run:
working-directory: offchain
steps:

- name: Install git
run : sudo apt update && sudo apt install git
working-directory: /

- uses: actions/checkout@v4
with:
submodules: recursive
Expand All @@ -49,6 +56,19 @@ jobs:
- name: 📦 Install protoc
run: sudo apt update && sudo apt install -y protobuf-compiler libprotobuf-dev

- name: Install Cartesi Machine
run : |
set -e
sudo apt update
sudo apt install -y --no-install-recommends \
ca-certificates \
curl
ARCH=$(dpkg --print-architecture)
curl -fsSL https://github.com/cartesi/machine-emulator/releases/download/v0.16.1/cartesi-machine-v0.16.1_${ARCH}.deb -o ./cartesi-machine.deb
apt-get install -y ./cartesi-machine.deb
rm ./cartesi-machine.deb
rm -rf /var/lib/apt/lists/*
- uses: actions/cache@v4
with:
path: |
Expand Down Expand Up @@ -102,76 +122,4 @@ jobs:
working-directory: ${{ github.workspace }}
run: go test ./...

build_docker:
runs-on: ubuntu-22.04
needs:
- test
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Docker meta
id: docker_meta
uses: docker/metadata-action@v5
with:
images: |
name=ghcr.io/cartesi/rollups-node
name=docker.io/cartesi/rollups-node,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
tags: |
type=semver,pattern={{version}}
type=ref,event=branch
type=ref,event=pr
- name: Login to Docker Hub
uses: docker/login-action@v3
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- uses: depot/setup-action@v1
- name: Build and push docker image
id: docker_build
uses: depot/bake-action@v1
with:
files: |
./docker-bake.hcl
${{ steps.docker_meta.outputs.bake-file }}
./docker-bake.platforms.hcl
targets: rollups-node
set: rollups-node.args.ROLLUPS_NODE_VERSION=${{ steps.docker_meta.outputs.version }}
push: true
project: ${{ vars.DEPOT_PROJECT }}
workdir: build

release:
needs: [test, build_docker]
runs-on: ubuntu-22.04
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Trim CHANGELOG.md
run: sed -e '0,/^##[^#]/d' -e '/^##[^#]/,$d' -i CHANGELOG.md

- name: Download GraphQL schema
uses: actions/download-artifact@v4
with:
name: graphql-schema

- name: Publish Github release
uses: softprops/action-gh-release@v2
with:
prerelease: true
body_path: CHANGELOG.md
files: schema.graphql

2 changes: 1 addition & 1 deletion cmd/cartesi-rollups-node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func main() {
}()

// start supervisor
if err := supervisor.Start(ctx, ready); err != nil {
if err := supervisor.Start(ctx, ready, ""); err != nil {
slog.Error("Node exited with an error", "error", err)
os.Exit(1)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/gen-devnet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func run(cmd *cobra.Command, args []string) {
s = append(s, newAnvilService(anvilStatePath))

supervisor := newSupervisorService(s)
if err := supervisor.Start(ctx, ready); err != nil {
if err := supervisor.Start(ctx, ready, ""); err != nil {
fmt.Printf("%s: %v", supervisor.Name, err)
cancel()
}
Expand Down
7 changes: 6 additions & 1 deletion internal/services/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,14 @@ type CommandService struct {
WorkDir string
}

func (s CommandService) Start(ctx context.Context, ready chan<- struct{}) error {
func (s CommandService) Start(ctx context.Context, ready chan<- struct{}, workDir string) error {
cmd := exec.CommandContext(ctx, s.Path, s.Args...)
cmd.Env = s.Env

if workDir != "" {
cmd.Dir = workDir
}

cmd.Stderr = newLineWriter(commandLogger{s.Name})
cmd.Stdout = newLineWriter(commandLogger{s.Name})
cmd.Cancel = func() error {
Expand Down
6 changes: 3 additions & 3 deletions internal/services/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (s *CommandServiceSuite) TestItStopsWhenContextIsCancelled() {
result := make(chan error)
ready := make(chan struct{})
go func() {
result <- service.Start(ctx, ready)
result <- service.Start(ctx, ready, "")
}()

// assert service started successfully
Expand Down Expand Up @@ -82,7 +82,7 @@ func (s *CommandServiceSuite) TestItTimesOut() {
result := make(chan error)
ready := make(chan struct{})
go func() {
result <- service.Start(ctx, ready)
result <- service.Start(ctx, ready, "")
}()

// expect timeout because of wrong port
Expand All @@ -106,7 +106,7 @@ func (s *CommandServiceSuite) TestItFailsToStartIfExecutableNotInPath() {
defer cancel()
ready := make(chan struct{})

err := service.Start(ctx, ready)
err := service.Start(ctx, ready, "")

s.ErrorIs(err, exec.ErrNotFound, "service exited for the wrong reason: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/services/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (s HttpService) String() string {
return s.Name
}

func (s HttpService) Start(ctx context.Context, ready chan<- struct{}) error {
func (s HttpService) Start(ctx context.Context, ready chan<- struct{}, workDir string) error {
server := http.Server{
Addr: s.Address,
Handler: s.Handler,
Expand Down
6 changes: 3 additions & 3 deletions internal/services/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *HttpServiceSuite) TestItStopsWhenContextIsClosed() {
result := make(chan error, 1)
ready := make(chan struct{}, 1)
go func() {
result <- service.Start(ctx, ready)
result <- service.Start(ctx, ready, "")
}()

select {
Expand Down Expand Up @@ -71,7 +71,7 @@ func (s *HttpServiceSuite) TestItRespondsToRequests() {
result := make(chan error, 1)
ready := make(chan struct{}, 1)
go func() {
result <- service.Start(ctx, ready)
result <- service.Start(ctx, ready, "")
}()

select {
Expand Down Expand Up @@ -103,7 +103,7 @@ func (s *HttpServiceSuite) TestItRespondsOngoingRequestsAfterContextIsClosed() {
result := make(chan error, 1)
ready := make(chan struct{}, 1)
go func() {
result <- service.Start(ctx, ready)
result <- service.Start(ctx, ready, "")
}()

select {
Expand Down
2 changes: 1 addition & 1 deletion internal/services/server-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type ServerManager struct {

const waitDelay = 200 * time.Millisecond

func (s ServerManager) Start(ctx context.Context, ready chan<- struct{}) error {
func (s ServerManager) Start(ctx context.Context, ready chan<- struct{}, workDir string) error {
cmd := exec.CommandContext(ctx, s.Path, s.Args...)
cmd.Env = s.Env
if s.WorkDir != "" {
Expand Down
2 changes: 1 addition & 1 deletion internal/services/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ type Service interface {
fmt.Stringer

// Starts a service and sends a message to the channel when ready
Start(ctx context.Context, ready chan<- struct{}) error
Start(ctx context.Context, ready chan<- struct{}, workDir string) error
}
4 changes: 2 additions & 2 deletions internal/services/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (s SupervisorService) String() string {
return s.Name
}

func (s SupervisorService) Start(ctx context.Context, ready chan<- struct{}) error {
func (s SupervisorService) Start(ctx context.Context, ready chan<- struct{}, workDir string) error {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
group, ctx := errgroup.WithContext(ctx)
Expand All @@ -64,7 +64,7 @@ Loop:
serviceReady := make(chan struct{}, 1)

group.Go(func() error {
err := service.Start(ctx, serviceReady)
err := service.Start(ctx, serviceReady, workDir)
if err != nil && !errors.Is(err, context.Canceled) {
slog.Error("Service exited with error",
"service", service,
Expand Down
16 changes: 8 additions & 8 deletions internal/services/supervisor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (s *SupervisorServiceSuite) TestItIsReadyAfterStartingAllServices() {

ready := make(chan struct{})
go func() {
_ = supervisor.Start(ctx, ready)
_ = supervisor.Start(ctx, ready, "")
}()

select {
Expand Down Expand Up @@ -97,7 +97,7 @@ func (s *SupervisorServiceSuite) TestItStopsAllServicesWhenContextIsCanceled() {
result := make(chan error)
ready := make(chan struct{})
go func() {
result <- supervisor.Start(ctx, ready)
result <- supervisor.Start(ctx, ready, "")
}()

select {
Expand Down Expand Up @@ -153,7 +153,7 @@ func (s *SupervisorServiceSuite) TestItStopsAllServicesIfAServiceStops() {
result := make(chan error, 1)
ready := make(chan struct{}, 1)
go func() {
result <- supervisor.Start(ctx, ready)
result <- supervisor.Start(ctx, ready, "")
}()

select {
Expand Down Expand Up @@ -199,7 +199,7 @@ func (s *SupervisorServiceSuite) TestItStopsCreatingServicesIfAServiceFailsToSta
result := make(chan error, 1)
ready := make(chan struct{}, 1)
go func() {
result <- supervisor.Start(ctx, ready)
result <- supervisor.Start(ctx, ready, "")
}()

select {
Expand Down Expand Up @@ -244,7 +244,7 @@ func (s *SupervisorServiceSuite) TestItStopsCreatingServicesIfContextIsCanceled(
result := make(chan error)
ready := make(chan struct{}, 1)
go func() {
result <- supervisor.Start(ctx, ready)
result <- supervisor.Start(ctx, ready, "")
}()

<-time.After(300 * time.Millisecond)
Expand Down Expand Up @@ -287,7 +287,7 @@ func (s *SupervisorServiceSuite) TestItTimesOutIfServiceTakesTooLongToBeReady()
result := make(chan error)
ready := make(chan struct{}, 1)
go func() {
result <- supervisor.Start(ctx, ready)
result <- supervisor.Start(ctx, ready, "")
}()

select {
Expand Down Expand Up @@ -321,7 +321,7 @@ func (s *SupervisorServiceSuite) TestItTimesOutIfServicesTakeTooLongToStop() {
result := make(chan error)
ready := make(chan struct{}, 1)
go func() {
result <- supervisor.Start(ctx, ready)
result <- supervisor.Start(ctx, ready, "")
}()

<-ready
Expand All @@ -339,7 +339,7 @@ type MockService struct {
ReadyDelay time.Duration
}

func (m *MockService) Start(ctx context.Context, ready chan<- struct{}) error {
func (m *MockService) Start(ctx context.Context, ready chan<- struct{}, workdir string) error {
if m.ReadyDelay >= 0 {
go func() {
<-time.After(m.ReadyDelay)
Expand Down

0 comments on commit 2acaddc

Please sign in to comment.