Skip to content

Commit cab9208

Browse files
committed
Fix tests
1 parent 0b6542c commit cab9208

File tree

3 files changed

+2
-47
lines changed

3 files changed

+2
-47
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ setup-kibana-fleet: ## Creates the agent and integration policies required to ru
101101

102102
.PHONY: docker-clean
103103
docker-clean: ## Try to remove provisioned nodes and assigned network
104-
@ docker compose -f $(COMPOSE_FILE) down
104+
@ docker compose -f $(COMPOSE_FILE) down -v
105105

106106
.PHONY: copy-kibana-ca
107107
copy-kibana-ca: ## Copy Kibana CA certificate to local machine

internal/elasticsearch/ml/job_state/acc_test.go

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
package job_state_test
22

33
import (
4-
"encoding/json"
54
"fmt"
6-
"maps"
75
"regexp"
8-
"slices"
96
"testing"
107

118
"github.com/elastic/terraform-provider-elasticstack/internal/acctest"
12-
"github.com/elastic/terraform-provider-elasticstack/internal/clients"
139
"github.com/hashicorp/terraform-plugin-testing/config"
1410
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1511
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1612
"github.com/hashicorp/terraform-plugin-testing/terraform"
17-
"github.com/stretchr/testify/require"
1813
)
1914

2015
func TestAccResourceMLJobState(t *testing.T) {
@@ -134,44 +129,9 @@ func TestAccResourceMLJobState_timeouts(t *testing.T) {
134129
ConfigVariables: config.Variables{
135130
"job_id": config.StringVariable(jobID),
136131
"index_name": config.StringVariable(indexName),
137-
"job_memory": config.StringVariable(GetMaxMLJobMemory(t)),
138132
},
139133
ExpectError: regexp.MustCompile("Operation timed out"),
140134
},
141135
},
142136
})
143137
}
144-
145-
func GetMaxMLJobMemory(t *testing.T) string {
146-
client, err := clients.NewAcceptanceTestingClient()
147-
require.NoError(t, err)
148-
149-
esClient, err := client.GetESClient()
150-
require.NoError(t, err)
151-
152-
resp, err := esClient.ML.GetMemoryStats()
153-
require.NoError(t, err)
154-
155-
defer resp.Body.Close()
156-
type mlNode struct {
157-
Memory struct {
158-
ML struct {
159-
MaxInBytes int64 `json:"max_in_bytes"`
160-
} `json:"ml"`
161-
} `json:"mem"`
162-
}
163-
var mlMemoryStats struct {
164-
Nodes map[string]mlNode `json:"nodes"`
165-
}
166-
167-
err = json.NewDecoder(resp.Body).Decode(&mlMemoryStats)
168-
require.NoError(t, err)
169-
170-
nodes := slices.Collect(maps.Values(mlMemoryStats.Nodes))
171-
nodeWithMaxMemory := slices.MaxFunc(nodes, func(a, b mlNode) int {
172-
return int(b.Memory.ML.MaxInBytes - a.Memory.ML.MaxInBytes)
173-
})
174-
175-
maxAvailableMemoryInMB := nodeWithMaxMemory.Memory.ML.MaxInBytes / (1024 * 1024)
176-
return fmt.Sprintf("%dmb", maxAvailableMemoryInMB+50)
177-
}

internal/elasticsearch/ml/job_state/testdata/TestAccResourceMLJobState_timeouts/timeouts/job_state.tf

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ variable "index_name" {
88
type = string
99
}
1010

11-
variable "job_memory" {
12-
description = "The ML job memory limit"
13-
type = string
14-
}
15-
1611
provider "elasticstack" {
1712
elasticsearch {}
1813
}
@@ -47,7 +42,7 @@ resource "elasticstack_elasticsearch_ml_anomaly_detection_job" "test" {
4742
time_format = "epoch_ms"
4843
}
4944
analysis_limits = {
50-
model_memory_limit = var.job_memory
45+
model_memory_limit = "2gb"
5146
}
5247
allow_lazy_open = true # This should cause datafeed to wait for available node
5348
}

0 commit comments

Comments
 (0)