Skip to content

Commit 48c6fa7

Browse files
authored
Enable cloud tests (#1202)
* Enable cloud tests * fixes * fixes * ensure select_sequential_consistency for some selects * The JSON data type is an obsolete feature. Skip tests on Cloud. * Mark flaky tests
1 parent fe7821d commit 48c6fa7

9 files changed

+100
-58
lines changed

main.tf .github/cloud/service.tf

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
terraform {
22
required_providers {
33
clickhouse = {
4-
source = "ClickHouse/clickhouse"
5-
version = "~> 0.0.2"
4+
source = "ClickHouse/clickhouse"
5+
version = "~> 0.0.5"
66
}
77
}
88
}
@@ -21,31 +21,40 @@ variable "token_secret" {
2121

2222
variable "service_name" {
2323
type = string
24+
default = "clickhouse-go-tests"
2425
}
2526

2627
variable "service_password" {
2728
type = string
2829
}
2930

30-
provider clickhouse {
31-
environment = "production"
31+
variable "api_url" {
32+
type = string
33+
}
34+
35+
variable "allowed_cidr" {
36+
type = string
37+
default = "0.0.0.0/0"
38+
}
39+
40+
provider "clickhouse" {
3241
organization_id = var.organization_id
3342
token_key = var.token_key
3443
token_secret = var.token_secret
44+
api_url = var.api_url
3545
}
3646

3747
resource "clickhouse_service" "service" {
3848
name = var.service_name
3949
cloud_provider = "aws"
4050
region = "us-east-2"
4151
tier = "development"
42-
idle_scaling = true
43-
password = var.service_password
52+
password = var.service_password
4453

4554
ip_access = [
4655
{
47-
source = "0.0.0.0/0"
48-
description = "Anywhere"
56+
source = var.allowed_cidr
57+
description = "Allowed CIDR"
4958
}
5059
]
5160
}

.github/workflows/run-tests.yml

+25-10
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ permissions: write-all
55
on:
66
push:
77
branches:
8-
- v1
98
- main
109
pull_request:
1110
branches:
12-
- v1
1311
- main
1412

1513
jobs:
@@ -41,7 +39,6 @@ jobs:
4139
CLICKHOUSE_VERSION=${{ matrix.clickhouse }} make test
4240
4341
integration-tests-cloud:
44-
if: ${{ false }} # disabled for now
4542
runs-on: [self-hosted, style-checker]
4643
defaults:
4744
run:
@@ -50,12 +47,15 @@ jobs:
5047
fail-fast: true
5148
matrix:
5249
go:
53-
- "1.19"
54-
- "1.20"
50+
- "1.22"
51+
- "1.21"
5552
steps:
5653
- name: Check Out Code
5754
uses: actions/checkout@v3
5855

56+
- name: Resolve runner IP
57+
run: echo "TF_VAR_allowed_cidr=$(curl -s ifconfig.me)/32" >> $GITHUB_ENV
58+
5959
- name: Setup Terraform
6060
uses: hashicorp/setup-terraform@v2.0.3
6161
with:
@@ -64,28 +64,41 @@ jobs:
6464

6565
- name: Terraform Init
6666
id: init
67+
working-directory: .github/cloud/
6768
run: terraform init
6869

6970
- name: Terraform Validate
7071
id: validate
72+
working-directory: .github/cloud/
7173
run: terraform validate -no-color
7274

73-
- name: Set Service Name
74-
run: echo "TF_VAR_service_name=go_client_tests_$(date +'%Y_%m_%d_%H_%M_%S')" >> $GITHUB_ENV
75+
- name: Set service name for pull request
76+
if: github.event_name == 'pull_request'
77+
working-directory: .github/cloud/
78+
run: echo "TF_VAR_service_name=clickhouse-go ${{ matrix.go }} PR${{ github.event.pull_request.number }} $(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV
79+
80+
- name: Set service name for push
81+
if: github.event_name == 'push'
82+
working-directory: .github/cloud/
83+
run: echo "TF_VAR_service_name=clickhouse-go ${{ matrix.go }} $(git rev-parse --short HEAD) $(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV
7584

7685
- name: Terraform Apply
86+
working-directory: .github/cloud/
7787
id: apply
78-
run: terraform apply -no-color -auto-approve
88+
run: terraform apply -no-color -auto-approve -input=false -lock=false
7989
env:
8090
TF_VAR_organization_id: ${{ secrets.INTEGRATIONS_TEAM_TESTS_ORGANIZATION_ID }}
8191
TF_VAR_token_key: ${{ secrets.INTEGRATIONS_TEAM_TESTS_TOKEN_KEY }}
8292
TF_VAR_token_secret: ${{ secrets.INTEGRATIONS_TEAM_TESTS_TOKEN_SECRET }}
8393
TF_VAR_service_password: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_PASSWORD }}
94+
TF_VAR_api_url: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_API_URL }}
8495

8596
- name: Set Host
97+
working-directory: .github/cloud/
8698
run: echo "CLICKHOUSE_HOST=$(terraform output -raw CLICKHOUSE_HOST)" >> $GITHUB_ENV
8799

88-
- name: Service Id
100+
- name: Service ID
101+
working-directory: .github/cloud/
89102
run: terraform output -raw SERVICE_ID
90103

91104
- name: Install Go ${{ matrix.go }}
@@ -104,9 +117,11 @@ jobs:
104117
105118
- name: Cleanup
106119
if: always()
107-
run: terraform destroy -no-color -auto-approve
120+
working-directory: .github/cloud/
121+
run: terraform destroy -no-color -auto-approve -input=false -lock=false
108122
env:
109123
TF_VAR_organization_id: ${{ secrets.INTEGRATIONS_TEAM_TESTS_ORGANIZATION_ID }}
110124
TF_VAR_token_key: ${{ secrets.INTEGRATIONS_TEAM_TESTS_TOKEN_KEY }}
111125
TF_VAR_token_secret: ${{ secrets.INTEGRATIONS_TEAM_TESTS_TOKEN_SECRET }}
112126
TF_VAR_service_password: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_PASSWORD }}
127+
TF_VAR_api_url: ${{ secrets.INTEGRATIONS_TEAM_TESTS_CLOUD_API_URL }}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ vendor
3636
.terraform.lock.hcl
3737
**/.terraform*
3838
pipeline.auto.tfvars
39+
*.tfvars
40+
41+
.env

tests/batch_release_connection_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ package tests
33
import (
44
"context"
55
"fmt"
6+
"testing"
7+
68
"github.com/ClickHouse/clickhouse-go/v2"
79
"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
810
"github.com/stretchr/testify/require"
9-
"testing"
1011
)
1112

1213
func TestBatchReleaseConnection(t *testing.T) {
14+
SkipOnCloud(t, "This test is flaky on cloud ClickHouse")
15+
1316
conn, err := GetNativeConnection(nil, nil, &clickhouse.Compression{
1417
Method: clickhouse.CompressionLZ4,
1518
})

tests/conn_test.go

+5-16
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,7 @@ func TestConnCustomDialStrategy(t *testing.T) {
266266
}
267267

268268
func TestEmptyDatabaseConfig(t *testing.T) {
269-
runInDocker, _ := strconv.ParseBool(GetEnv("CLICKHOUSE_USE_DOCKER", "true"))
270-
if !runInDocker {
271-
t.Skip("Skip test in cloud environment.")
272-
}
269+
SkipOnCloud(t)
273270

274271
env, err := GetNativeTestEnvironment()
275272
require.NoError(t, err)
@@ -309,10 +306,7 @@ func TestEmptyDatabaseConfig(t *testing.T) {
309306
}
310307

311308
func TestCustomSettings(t *testing.T) {
312-
runInDocker, _ := strconv.ParseBool(GetEnv("CLICKHOUSE_USE_DOCKER", "true"))
313-
if !runInDocker {
314-
t.Skip("Skip test in cloud environment.") // todo configure cloud instance with custom settings
315-
}
309+
SkipOnCloud(t, "Custom settings are not supported on ClickHouse Cloud")
316310

317311
conn, err := GetNativeConnection(clickhouse.Settings{
318312
"custom_setting": clickhouse.CustomSetting{"custom_value"},
@@ -350,10 +344,7 @@ func TestCustomSettings(t *testing.T) {
350344
}
351345

352346
func TestConnectionExpiresIdleConnection(t *testing.T) {
353-
runInDocker, _ := strconv.ParseBool(GetEnv("CLICKHOUSE_USE_DOCKER", "true"))
354-
if !runInDocker {
355-
t.Skip("Skip test in cloud environment. This test is not stable in cloud environment, due to race conditions.")
356-
}
347+
SkipOnCloud(t)
357348

358349
// given
359350
ctx := context.Background()
@@ -404,10 +395,8 @@ func getActiveConnections(t *testing.T, client clickhouse.Conn) (conns int64) {
404395
}
405396

406397
func TestConnectionCloseIdle(t *testing.T) {
407-
runInDocker, _ := strconv.ParseBool(GetEnv("CLICKHOUSE_USE_DOCKER", "true"))
408-
if !runInDocker {
409-
t.Skip("Skip test in cloud environment. This test is not stable in cloud environment, due to race conditions.")
410-
}
398+
SkipOnCloud(t)
399+
411400
testEnv, err := GetTestEnvironment(testSet)
412401
require.NoError(t, err)
413402
baseGoroutine := runtime.NumGoroutine()

tests/custom_dial_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func TestCustomDialContext(t *testing.T) {
5858
dialCount++
5959
var d net.Dialer
6060
if tlsConfig != nil {
61-
return tls.DialWithDialer(&net.Dialer{Timeout: time.Duration(5) * time.Second}, "tcp", addr, tlsConfig)
61+
return tls.DialWithDialer(&net.Dialer{Timeout: time.Duration(30) * time.Second}, "tcp", addr, tlsConfig)
6262
}
6363
return d.DialContext(ctx, "tcp", addr)
6464
},

tests/json_test.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ import (
2121
"context"
2222
"encoding/json"
2323
"fmt"
24+
"log"
25+
"net"
26+
"testing"
27+
"time"
28+
2429
"github.com/ClickHouse/clickhouse-go/v2"
2530
"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
2631
"github.com/google/uuid"
2732
"github.com/shopspring/decimal"
2833
"github.com/stretchr/testify/assert"
2934
"github.com/stretchr/testify/require"
30-
"log"
31-
"net"
32-
"testing"
33-
"time"
3435
)
3536

3637
type Releases struct {
@@ -67,6 +68,8 @@ type GithubEvent struct {
6768
var testDate, _ = time.Parse("2006-01-02 15:04:05.999999999 -0700 MST", "2022-05-25 17:20:57 +0100 WEST")
6869

6970
func setupConnection(t *testing.T) driver.Conn {
71+
SkipOnCloud(t, "The JSON data type is an obsolete feature on Cloud.")
72+
7073
conn, err := GetNativeConnection(clickhouse.Settings{
7174
"allow_experimental_object_type": 1,
7275
}, nil, nil)

tests/package.go

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package tests
2+
3+
import (
4+
"os"
5+
"strings"
6+
"testing"
7+
)
8+
9+
var LocalClickHouse = false
10+
var RemoteClickHouse = false
11+
var CloudClickHouse = false
12+
13+
func init() {
14+
if host, found := os.LookupEnv("CLICKHOUSE_HOST"); found {
15+
if strings.HasSuffix(host, "clickhouse.cloud") ||
16+
strings.HasSuffix(host, "clickhouse-staging.com") {
17+
CloudClickHouse = true
18+
} else {
19+
RemoteClickHouse = true
20+
}
21+
} else {
22+
LocalClickHouse = true
23+
}
24+
}
25+
26+
func SkipOnCloud(t *testing.T, reasons ...string) {
27+
if CloudClickHouse {
28+
t.Skip(append(
29+
[]string{"Skipping test on cloud ClickHouse"},
30+
reasons...,
31+
))
32+
}
33+
}

tests/std/conn_test.go

+5-18
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,7 @@ func TestMaxExecutionTime(t *testing.T) {
289289
}
290290

291291
func TestHttpConnWithOptions(t *testing.T) {
292-
runInDocker, _ := strconv.ParseBool(clickhouse_tests.GetEnv("CLICKHOUSE_USE_DOCKER", "true"))
293-
if !runInDocker {
294-
t.Skip("Skip test in cloud environment.")
295-
}
292+
clickhouse_tests.SkipOnCloud(t)
296293

297294
env, err := GetStdTestEnvironment()
298295
require.NoError(t, err)
@@ -327,10 +324,7 @@ func TestHttpConnWithOptions(t *testing.T) {
327324
}
328325

329326
func TestEmptyDatabaseConfig(t *testing.T) {
330-
runInDocker, _ := strconv.ParseBool(clickhouse_tests.GetEnv("CLICKHOUSE_USE_DOCKER", "true"))
331-
if !runInDocker {
332-
t.Skip("Skip test in cloud environment.")
333-
}
327+
clickhouse_tests.SkipOnCloud(t)
334328

335329
env, err := GetStdTestEnvironment()
336330
require.NoError(t, err)
@@ -371,11 +365,7 @@ func TestEmptyDatabaseConfig(t *testing.T) {
371365
func TestHTTPProxy(t *testing.T) {
372366
t.Skip("test is flaky, tinyproxy container can't be started in CI")
373367

374-
// check if CLICKHOUSE_HOST env is postfixed with "clickhouse.cloud", skip if not
375-
clickHouseHost := clickhouse_tests.GetEnv("CLICKHOUSE_HOST", "")
376-
if !strings.HasSuffix(clickHouseHost, "clickhouse.cloud") {
377-
t.Skip("Skip test in non cloud environment.")
378-
}
368+
clickhouse_tests.SkipOnCloud(t)
379369

380370
proxyEnv, err := clickhouse_tests.CreateTinyProxyTestEnvironment(t)
381371
defer func() {
@@ -415,15 +405,12 @@ func TestHTTPProxy(t *testing.T) {
415405

416406
text := scanner.Text()
417407
t.Log(text)
418-
return strings.Contains(text, fmt.Sprintf("Established connection to host \"%s\"", clickHouseHost))
408+
return strings.Contains(text, fmt.Sprintf("Established connection to host \"%s\"", ""))
419409
}, 60*time.Second, time.Millisecond, "proxy logs should contain clickhouse.cloud instance host")
420410
}
421411

422412
func TestCustomSettings(t *testing.T) {
423-
runInDocker, _ := strconv.ParseBool(clickhouse_tests.GetEnv("CLICKHOUSE_USE_DOCKER", "true"))
424-
if !runInDocker {
425-
t.Skip("Skip test in cloud environment.")
426-
}
413+
clickhouse_tests.SkipOnCloud(t)
427414

428415
dsns := map[string]clickhouse.Protocol{"Native": clickhouse.Native, "Http": clickhouse.HTTP}
429416
for name, protocol := range dsns {

0 commit comments

Comments
 (0)