Skip to content

Commit 209c91b

Browse files
committed
TEST/MEDIUM: e2e: tests to check parallel reads on runtime work
1 parent 8500ef9 commit 209c91b

File tree

4 files changed

+129
-0
lines changed

4 files changed

+129
-0
lines changed

e2e/runtime/parallel/haproxy.cfg

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
global
2+
maxconn 1000
3+
stats socket "$SOCK_PATH" level admin
4+
5+
defaults
6+
mode http
7+
8+
frontend test
9+
bind localhost:32000
10+
default_backend test_bck
11+
12+
backend test_bck
13+
balance roundrobin
14+
server test1 127.0.0.1:5000
15+
server test2 127.0.0.1:5001

e2e/runtime/parallel/parallel_test.go

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2021 HAProxy Technologies
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
//go:build integration
16+
// +build integration
17+
18+
package parallel_test
19+
20+
import (
21+
"sync"
22+
)
23+
24+
func (s *ParallelRuntime) TestParallel() {
25+
runtime, err := s.client.Runtime()
26+
if err != nil {
27+
s.FailNow(err.Error())
28+
}
29+
var wg sync.WaitGroup
30+
for range 3000 {
31+
wg.Add(1)
32+
go func() {
33+
defer wg.Done()
34+
info, err := runtime.GetInfo()
35+
s.Assert().Empty(info.Error, "error is: ", info.Error)
36+
s.Assert().NotNil(info.Info, "information is nil", info.Error)
37+
s.Assert().Equal(info.RuntimeAPI, s.socketPath, "runtime not correct, runtime is ", info.RuntimeAPI)
38+
s.Assert().Contains(info.Info.Version, s.haproxyVersion, "version not correct, version is ", info.Info.Version)
39+
if err != nil {
40+
s.FailNow(err.Error())
41+
}
42+
}()
43+
}
44+
wg.Wait()
45+
}

e2e/runtime/parallel/setup_test.go

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright 2021 HAProxy Technologies
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
//go:build integration
16+
// +build integration
17+
18+
package parallel_test
19+
20+
import (
21+
"os"
22+
"os/exec"
23+
"testing"
24+
25+
client_native "github.com/haproxytech/client-native/v6"
26+
27+
"github.com/haproxytech/client-native/v6/e2e"
28+
"github.com/stretchr/testify/suite"
29+
)
30+
31+
type ParallelRuntime struct {
32+
suite.Suite
33+
cmd *exec.Cmd
34+
client client_native.HAProxyClient
35+
tmpDir string
36+
haproxyVersion string
37+
socketPath string
38+
}
39+
40+
func (s *ParallelRuntime) SetupTest() {
41+
result, err := e2e.GetClient(s.T())
42+
if err != nil {
43+
s.FailNow(err.Error())
44+
}
45+
s.haproxyVersion = result.HAProxyVersion
46+
s.cmd = result.Cmd
47+
s.client = result.Client
48+
s.tmpDir = result.TmpDir
49+
s.socketPath = result.SocketPath
50+
}
51+
52+
func (s *ParallelRuntime) TearDownSuite() {
53+
if err := s.cmd.Process.Kill(); err != nil {
54+
s.FailNow(err.Error())
55+
}
56+
if s.tmpDir != "" {
57+
err := os.RemoveAll(s.tmpDir)
58+
if err != nil {
59+
s.FailNow(err.Error())
60+
}
61+
}
62+
}
63+
64+
func TestParallelRuntimes(t *testing.T) {
65+
suite.Run(t, new(ParallelRuntime))
66+
}

e2e/test_client.go

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type ClientResponse struct {
4242
Cmd *exec.Cmd
4343
TmpDir string
4444
HAProxyVersion string
45+
SocketPath string
4546
}
4647

4748
func GetClient(t *testing.T) (*ClientResponse, error) { //nolint:thelper
@@ -72,6 +73,7 @@ func GetClient(t *testing.T) (*ClientResponse, error) { //nolint:thelper
7273

7374
tmpPath := path.Join(os.TempDir(), "client-native/", testName)
7475
socketPath := path.Join(tmpPath, "runtime.sock")
76+
7577
err = os.MkdirAll(tmpPath, 0o777)
7678
if err != nil {
7779
return nil, err
@@ -131,5 +133,6 @@ func GetClient(t *testing.T) (*ClientResponse, error) { //nolint:thelper
131133
Cmd: cmd,
132134
TmpDir: tmpPath,
133135
HAProxyVersion: version,
136+
SocketPath: socketPath,
134137
}, err
135138
}

0 commit comments

Comments
 (0)