Skip to content

Commit 917aee4

Browse files
authored
Skip np cache in VCR and revert VCR CI change (#15494)
1 parent 6091161 commit 917aee4

File tree

3 files changed

+16
-58
lines changed

3 files changed

+16
-58
lines changed

.ci/magician/cmd/test_terraform_vcr.go

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -450,65 +450,16 @@ func modifiedPackages(changedFiles []string, version provider.Version) (map[stri
450450
return services, runFullVCR
451451
}
452452

453-
func allSubFolders(root string) (map[string]struct{}, error) {
454-
subfolders := make(map[string]struct{})
455-
entries, err := os.ReadDir(root)
456-
if err != nil {
457-
return nil, fmt.Errorf("failed to read directory '%s': %w", root, err)
458-
}
459-
460-
for _, entry := range entries {
461-
if entry.IsDir() {
462-
subfolders[entry.Name()] = struct{}{}
463-
}
464-
}
465-
return subfolders, nil
466-
}
467-
468453
func runReplaying(runFullVCR bool, version provider.Version, services map[string]struct{}, vt *vcr.Tester) (vcr.Result, []string, error) {
469454
result := vcr.Result{}
470455
var testDirs []string
471456
var replayingErr error
472457
if runFullVCR {
473458
fmt.Println("runReplaying: full VCR tests")
474-
// result, replayingErr = vt.Run(vcr.RunOptions{
475-
// Mode: vcr.Replaying,
476-
// Version: version,
477-
// })
478-
479-
// temporary workaround
480-
serviceRoot := filepath.Join(vt.GetRepoPath(version), version.ProviderName(), "services")
481-
allServies, err := allSubFolders(serviceRoot)
482-
if err != nil {
483-
return result, testDirs, err
484-
}
485-
486-
var gkePath string
487-
var otherPaths []string
488-
for service := range allServies {
489-
servicePath := "./" + filepath.Join(version.ProviderName(), "services", service)
490-
if service == "container" {
491-
gkePath = servicePath
492-
continue
493-
}
494-
otherPaths = append(otherPaths, servicePath)
495-
}
496459
result, replayingErr = vt.Run(vcr.RunOptions{
497-
Mode: vcr.Replaying,
498-
Version: version,
499-
TestDirs: otherPaths,
500-
})
501-
// run gke replaying tests separately
502-
gkeResult, gkeReplayingErr := vt.Run(vcr.RunOptions{
503-
Mode: vcr.Replaying,
504-
Version: version,
505-
TestDirs: []string{gkePath},
460+
Mode: vcr.Replaying,
461+
Version: version,
506462
})
507-
replayingErr = errors.Join(replayingErr, gkeReplayingErr)
508-
result.PassedTests = append(result.PassedTests, gkeResult.PassedTests...)
509-
result.SkippedTests = append(result.SkippedTests, gkeResult.SkippedTests...)
510-
result.FailedTests = append(result.FailedTests, gkeResult.FailedTests...)
511-
result.Panics = append(result.Panics, gkeResult.Panics...)
512463
} else if len(services) > 0 {
513464
fmt.Printf("runReplaying: %d specific services: %v\n", len(services), services)
514465
for service := range services {

.ci/magician/vcr/tester.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,6 @@ func (vt *Tester) SetRepoPath(version provider.Version, repoPath string) {
140140
vt.repoPaths[version] = repoPath
141141
}
142142

143-
func (vt *Tester) GetRepoPath(version provider.Version) string {
144-
return vt.repoPaths[version]
145-
}
146-
147143
// Fetch the cassettes for the current version if not already fetched.
148144
// Should be run from the base dir.
149145
func (vt *Tester) FetchCassettes(version provider.Version, baseBranch, head string) error {

mmv1/third_party/terraform/services/container/resource_container_node_pool.go.tmpl

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package container
22

33
import (
44
{{- if ne $.TargetVersionName `ga` }}
5-
"context"
5+
"context"
6+
"os"
67
{{- end }}
78
"fmt"
89
"log"
@@ -159,14 +160,24 @@ func (instanceGroupManagerCache *instanceGroupManagerCache) needsRefresh(fullyQu
159160
return time.Since(igm.updateTime) > instanceGroupManagerCache.ttl
160161
}
161162

163+
// We need to set ttl to 0 to disable caching in VCR testing.
164+
// This ensure all NP/MIG LIST requests are made consistently,
165+
// preventing non-deterministic behavior that would break VCR.
166+
func getCacheTTL() time.Duration {
167+
if os.Getenv("VCR_PATH") != "" && os.Getenv("VCR_MODE") != "" {
168+
return 0 * time.Second
169+
}
170+
return 30 * time.Second
171+
}
172+
162173
var (
163174
npCache = &nodePoolCache{
164175
nodePools: make(map[string]*nodePoolWithUpdateTime),
165-
ttl: 30 * time.Second,
176+
ttl: getCacheTTL(),
166177
}
167178
igmCache = &instanceGroupManagerCache{
168179
instanceGroupManagers: make(map[string]*instanceGroupManagerWithUpdateTime),
169-
ttl: 30 * time.Second,
180+
ttl: getCacheTTL(),
170181
}
171182
)
172183
{{- end }}

0 commit comments

Comments
 (0)