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 8, 2024
1 parent 8500ef9 commit 209c91b
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 0 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().Empty(info.Error, "error is: ", info.Error)
s.Assert().NotNil(info.Info, "information is nil", info.Error)
s.Assert().Equal(info.RuntimeAPI, s.socketPath, "runtime not correct, runtime is ", info.RuntimeAPI)
s.Assert().Contains(info.Info.Version, s.haproxyVersion, "version not correct, version is ", info.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/v6"

"github.com/haproxytech/client-native/v6/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) { //nolint:thelper
Expand Down Expand Up @@ -72,6 +73,7 @@ func GetClient(t *testing.T) (*ClientResponse, error) { //nolint:thelper

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) { //nolint:thelper
Cmd: cmd,
TmpDir: tmpPath,
HAProxyVersion: version,
SocketPath: socketPath,
}, err
}

0 comments on commit 209c91b

Please sign in to comment.