|
1 | 1 | package job_state_test |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "encoding/json" |
5 | 4 | "fmt" |
6 | | - "maps" |
7 | 5 | "regexp" |
8 | | - "slices" |
9 | 6 | "testing" |
10 | 7 |
|
11 | 8 | "github.com/elastic/terraform-provider-elasticstack/internal/acctest" |
12 | | - "github.com/elastic/terraform-provider-elasticstack/internal/clients" |
13 | 9 | "github.com/hashicorp/terraform-plugin-testing/config" |
14 | 10 | sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" |
15 | 11 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
16 | 12 | "github.com/hashicorp/terraform-plugin-testing/terraform" |
17 | | - "github.com/stretchr/testify/require" |
18 | 13 | ) |
19 | 14 |
|
20 | 15 | func TestAccResourceMLJobState(t *testing.T) { |
@@ -134,44 +129,9 @@ func TestAccResourceMLJobState_timeouts(t *testing.T) { |
134 | 129 | ConfigVariables: config.Variables{ |
135 | 130 | "job_id": config.StringVariable(jobID), |
136 | 131 | "index_name": config.StringVariable(indexName), |
137 | | - "job_memory": config.StringVariable(GetMaxMLJobMemory(t)), |
138 | 132 | }, |
139 | 133 | ExpectError: regexp.MustCompile("Operation timed out"), |
140 | 134 | }, |
141 | 135 | }, |
142 | 136 | }) |
143 | 137 | } |
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 | | -} |
0 commit comments