Skip to content

Commit

Permalink
TEST/MEDIUM: e2e: tests to check parallel reads on runtime work
Browse files Browse the repository at this point in the history
  • Loading branch information
mjuraga committed Oct 9, 2024
1 parent 2e45653 commit 08f0d19
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 2 deletions.
15 changes: 15 additions & 0 deletions e2e/runtime/parallel/haproxy.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
global
maxconn 1000
stats socket "$SOCK_PATH" level admin

defaults
mode http

frontend test
bind localhost:32000
default_backend test_bck

backend test_bck
balance roundrobin
server test1 127.0.0.1:5000
server test2 127.0.0.1:5001
45 changes: 45 additions & 0 deletions e2e/runtime/parallel/parallel_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2021 HAProxy Technologies
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//go:build integration
// +build integration

package parallel_test

import (
"sync"
)

func (s *ParallelRuntime) TestParallel() {
runtime, err := s.client.Runtime()
if err != nil {
s.FailNow(err.Error())
}
var wg sync.WaitGroup
for range 3000 {
wg.Add(1)
go func() {
defer wg.Done()
info, err := runtime.GetInfo()
s.Assert().Greater(len(info), 0, "info is empty")
s.Assert().NotNil(info[0].Info, "information is nil", info[0].Error)
s.Assert().Equal(info[0].RuntimeAPI, s.socketPath, "runtime not correct, runtime is ", info[0].RuntimeAPI)
s.Assert().Contains(info[0].Info.Version, s.haproxyVersion, "version not correct, version is ", info[0].Info.Version)
if err != nil {
s.FailNow(err.Error())
}
}()
}
wg.Wait()
}
66 changes: 66 additions & 0 deletions e2e/runtime/parallel/setup_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2021 HAProxy Technologies
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//go:build integration
// +build integration

package parallel_test

import (
"os"
"os/exec"
"testing"

client_native "github.com/haproxytech/client-native/v5"

"github.com/haproxytech/client-native/v5/e2e"
"github.com/stretchr/testify/suite"
)

type ParallelRuntime struct {
suite.Suite
cmd *exec.Cmd
client client_native.HAProxyClient
tmpDir string
haproxyVersion string
socketPath string
}

func (s *ParallelRuntime) SetupTest() {
result, err := e2e.GetClient(s.T())
if err != nil {
s.FailNow(err.Error())
}
s.haproxyVersion = result.HAProxyVersion
s.cmd = result.Cmd
s.client = result.Client
s.tmpDir = result.TmpDir
s.socketPath = result.SocketPath
}

func (s *ParallelRuntime) TearDownSuite() {
if err := s.cmd.Process.Kill(); err != nil {
s.FailNow(err.Error())
}
if s.tmpDir != "" {
err := os.RemoveAll(s.tmpDir)
if err != nil {
s.FailNow(err.Error())
}
}
}

func TestParallelRuntimes(t *testing.T) {
suite.Run(t, new(ParallelRuntime))
}
3 changes: 3 additions & 0 deletions e2e/test_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type ClientResponse struct {
Cmd *exec.Cmd
TmpDir string
HAProxyVersion string
SocketPath string
}

func GetClient(t *testing.T) (*ClientResponse, error) {
Expand Down Expand Up @@ -72,6 +73,7 @@ func GetClient(t *testing.T) (*ClientResponse, error) {

tmpPath := path.Join(os.TempDir(), "client-native/", testName)
socketPath := path.Join(tmpPath, "runtime.sock")

err = os.MkdirAll(tmpPath, 0o777)
if err != nil {
return nil, err
Expand Down Expand Up @@ -131,5 +133,6 @@ func GetClient(t *testing.T) (*ClientResponse, error) {
Cmd: cmd,
TmpDir: tmpPath,
HAProxyVersion: version,
SocketPath: socketPath,
}, err
}
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module github.com/haproxytech/client-native/v5

go 1.22.0

toolchain go1.22.7

require (
github.com/go-faker/faker/v4 v4.5.0
github.com/go-openapi/errors v0.22.0
Expand Down

0 comments on commit 08f0d19

Please sign in to comment.