@@ -17,11 +17,13 @@ type cpvMockJobsdb struct {
17
17
JobsDB
18
18
}
19
19
20
- func (j * cpvMockJobsdb ) GetDistinctParameterValues (ctx context.Context , parameterName string ) ([]string , error ) {
20
+ func (j * cpvMockJobsdb ) GetDistinctParameterValues (ctx context.Context , parameter ParameterName ) ([]string , error ) {
21
21
j .calls ++
22
22
return []string {"value1" , "value2" }, nil
23
23
}
24
24
25
+ var testParameter parameterName = "test_parameter"
26
+
25
27
func TestCachingDistinctParameterValuesJobsdb (t * testing.T ) {
26
28
t .Run ("single goroutine" , func (t * testing.T ) {
27
29
// Create a mock JobsDB
@@ -34,20 +36,20 @@ func TestCachingDistinctParameterValuesJobsdb(t *testing.T) {
34
36
ctx := context .Background ()
35
37
36
38
// First call should fetch from the mock JobsDB
37
- values , err := cachingJobsdb .GetDistinctParameterValues (ctx , "test_parameter" )
39
+ values , err := cachingJobsdb .GetDistinctParameterValues (ctx , testParameter )
38
40
require .NoError (t , err )
39
41
require .Equal (t , 1 , jobsdb .calls )
40
42
require .Equal (t , []string {"value1" , "value2" }, values )
41
43
42
44
// Second call should hit the cache
43
- values , err = cachingJobsdb .GetDistinctParameterValues (ctx , "test_parameter" )
45
+ values , err = cachingJobsdb .GetDistinctParameterValues (ctx , testParameter )
44
46
require .NoError (t , err )
45
47
require .Equal (t , 1 , jobsdb .calls )
46
48
require .Equal (t , []string {"value1" , "value2" }, values )
47
49
48
50
time .Sleep (100 * time .Millisecond )
49
51
50
- values , err = cachingJobsdb .GetDistinctParameterValues (ctx , "test_parameter" )
52
+ values , err = cachingJobsdb .GetDistinctParameterValues (ctx , testParameter )
51
53
require .NoError (t , err )
52
54
require .Equal (t , 2 , jobsdb .calls )
53
55
require .Equal (t , []string {"value1" , "value2" }, values )
@@ -67,21 +69,21 @@ func TestCachingDistinctParameterValuesJobsdb(t *testing.T) {
67
69
for i := range 10 {
68
70
go func (i int ) {
69
71
defer wg .Done ()
70
- values , err := cachingJobsdb .GetDistinctParameterValues (ctx , "test_parameter_" + strconv .Itoa (i ))
72
+ values , err := cachingJobsdb .GetDistinctParameterValues (ctx , parameterName ( "test_parameter_" + strconv .Itoa (i ) ))
71
73
require .NoError (t , err )
72
74
require .Equal (t , []string {"value1" , "value2" }, values )
73
75
time .Sleep (100 * time .Millisecond )
74
- values , err = cachingJobsdb .GetDistinctParameterValues (ctx , "test_parameter_" + strconv .Itoa (i ))
76
+ values , err = cachingJobsdb .GetDistinctParameterValues (ctx , parameterName ( "test_parameter_" + strconv .Itoa (i ) ))
75
77
require .NoError (t , err )
76
78
require .Equal (t , []string {"value1" , "value2" }, values )
77
79
}(i )
78
80
go func (i int ) {
79
81
defer wg .Done ()
80
- values , err := cachingJobsdb .GetDistinctParameterValues (ctx , "test_parameter_" + strconv .Itoa (i ))
82
+ values , err := cachingJobsdb .GetDistinctParameterValues (ctx , parameterName ( "test_parameter_" + strconv .Itoa (i ) ))
81
83
require .NoError (t , err )
82
84
require .Equal (t , []string {"value1" , "value2" }, values )
83
85
time .Sleep (100 * time .Millisecond )
84
- values , err = cachingJobsdb .GetDistinctParameterValues (ctx , "test_parameter_" + strconv .Itoa (i ))
86
+ values , err = cachingJobsdb .GetDistinctParameterValues (ctx , parameterName ( "test_parameter_" + strconv .Itoa (i ) ))
85
87
require .NoError (t , err )
86
88
require .Equal (t , []string {"value1" , "value2" }, values )
87
89
}(i )
0 commit comments