@@ -61,6 +61,18 @@ func (d *threadSafeDSMock) InsertCVEForCPE(ctx context.Context, cve string, cpes
61
61
return d .Store .InsertCVEForCPE (ctx , cve , cpes )
62
62
}
63
63
64
+ func withNetRetry (t * testing.T , fn func () error ) error {
65
+ for {
66
+ err := fn ()
67
+ if err != nil && nettest .Retryable (err ) {
68
+ time .Sleep (5 * time .Second )
69
+ t .Logf ("%s: retrying error: %s" , t .Name (), err )
70
+ continue
71
+ }
72
+ return err
73
+ }
74
+ }
75
+
64
76
func TestTranslateCPEToCVE (t * testing.T ) {
65
77
nettest .Run (t )
66
78
@@ -71,7 +83,9 @@ func TestTranslateCPEToCVE(t *testing.T) {
71
83
72
84
// download the CVEs once for all sub-tests, and then disable syncing
73
85
cfg := config.FleetConfig {}
74
- err := SyncCVEData (tempDir , cfg )
86
+ err := withNetRetry (t , func () error {
87
+ return SyncCVEData (tempDir , cfg )
88
+ })
75
89
require .NoError (t , err )
76
90
cfg .Vulnerabilities .DisableDataSync = true
77
91
cfg .Vulnerabilities .RecentVulnerabilityMaxAge = 365 * 24 * time .Hour
@@ -93,14 +107,8 @@ func TestTranslateCPEToCVE(t *testing.T) {
93
107
return 0 , nil
94
108
}
95
109
96
- for {
97
- _ , err := TranslateCPEToCVE (ctx , ds , tempDir , kitlog .NewLogfmtLogger (os .Stdout ), cfg , false )
98
- if err != nil && nettest .Retryable (err ) {
99
- continue
100
- }
101
- require .NoError (t , err )
102
- break
103
- }
110
+ _ , err := TranslateCPEToCVE (ctx , ds , tempDir , kitlog .NewLogfmtLogger (os .Stdout ), cfg , false )
111
+ require .NoError (t , err )
104
112
105
113
printMemUsage ()
106
114
0 commit comments