@@ -26,8 +26,6 @@ const (
26
26
http_port 9090
27
27
https_port 9443
28
28
}
29
- localhost:9090 {
30
- }
31
29
`
32
30
caddyfilePattern = `
33
31
{
@@ -382,7 +380,7 @@ caching {
382
380
tester .InitServer (fmt .Sprintf (caddyfilePattern , config ), "caddyfile" )
383
381
384
382
for _ , testCase := range testCases {
385
- <- time .After (testCase .executeAfter )
383
+ <- time .After (testCase .executeAfter ) // wait for caching in background
386
384
387
385
r , _ := http .NewRequest (
388
386
"POST" ,
@@ -410,6 +408,7 @@ func (s *HandlerIntegrationTestSuite) TestCachingEnabledAutoInvalidate() {
410
408
const mutationPayload = `{"query": "mutation InvalidateUsers { updateUsers { id } }"}`
411
409
testCases := []struct {
412
410
name string
411
+ executeAfter time.Duration
413
412
expectedHitTimes string
414
413
expectedCachingStatus CachingStatus
415
414
expectedBody string
@@ -430,6 +429,7 @@ func (s *HandlerIntegrationTestSuite) TestCachingEnabledAutoInvalidate() {
430
429
expectedHitTimes : "1" ,
431
430
payload : payloadNameOnly ,
432
431
expectedCachingTags : `field:QueryTest:users, field:UserTest:name, operation:UsersNameOnly, schema:4230843191964202593, type:QueryTest, type:UserTest` ,
432
+ executeAfter : time .Millisecond * 5 ,
433
433
},
434
434
{
435
435
name : "type_keys_miss_on_first_time" ,
@@ -444,6 +444,7 @@ func (s *HandlerIntegrationTestSuite) TestCachingEnabledAutoInvalidate() {
444
444
expectedHitTimes : "1" ,
445
445
payload : payload ,
446
446
expectedCachingTags : `field:QueryTest:users, field:UserTest:id, field:UserTest:name, key:UserTest:id:1, key:UserTest:id:2, key:UserTest:id:3, operation:Users, schema:4230843191964202593, type:QueryTest, type:UserTest` ,
447
+ executeAfter : time .Millisecond * 5 ,
447
448
},
448
449
{
449
450
name : "mutation_invalidate_query_result" ,
@@ -483,6 +484,8 @@ caching {
483
484
tester .InitServer (fmt .Sprintf (caddyfilePattern , config ), "caddyfile" )
484
485
485
486
for _ , testCase := range testCases {
487
+ <- time .After (testCase .executeAfter ) // wait for caching in background
488
+
486
489
r , _ := http .NewRequest (
487
490
"POST" ,
488
491
"http://localhost:9090/graphql" ,
@@ -512,6 +515,7 @@ func (s *HandlerIntegrationTestSuite) TestCachingDisabledAutoInvalidate() {
512
515
const mutationPayload = `{"query": "mutation InvalidateUsers { updateUsers { id } }"}`
513
516
testCases := []struct {
514
517
name string
518
+ executeAfter time.Duration
515
519
expectedHitTimes string
516
520
expectedCachingStatus CachingStatus
517
521
expectedBody string
@@ -530,6 +534,7 @@ func (s *HandlerIntegrationTestSuite) TestCachingDisabledAutoInvalidate() {
530
534
expectedBody : `{"data":{"users":[{"id":1,"name":"A"},{"id":2,"name":"B"},{"id":3,"name":"C"}]}}` ,
531
535
expectedHitTimes : "1" ,
532
536
payload : payload ,
537
+ executeAfter : time .Millisecond * 5 ,
533
538
},
534
539
{
535
540
name : "mutation_invalidated_query_result_disabled" ,
@@ -562,6 +567,8 @@ caching {
562
567
tester .InitServer (fmt .Sprintf (caddyfilePattern , config ), "caddyfile" )
563
568
564
569
for _ , testCase := range testCases {
570
+ <- time .After (testCase .executeAfter ) // wait for caching in background
571
+
565
572
r , _ := http .NewRequest (
566
573
"POST" ,
567
574
"http://localhost:9090/graphql" ,
@@ -587,6 +594,7 @@ caching {
587
594
func (s * HandlerIntegrationTestSuite ) TestCachingVaries () {
588
595
testCases := []struct {
589
596
name string
597
+ executeAfter time.Duration
590
598
expectedHitTimes string
591
599
expectedCachingStatus CachingStatus
592
600
expectedBody string
@@ -605,6 +613,7 @@ func (s *HandlerIntegrationTestSuite) TestCachingVaries() {
605
613
expectedCachingStatus : CachingStatusHit ,
606
614
expectedBody : `{"data":{"users":[{"name":"A"},{"name":"B"},{"name":"C"}]}}` ,
607
615
expectedHitTimes : "1" ,
616
+ executeAfter : time .Millisecond * 5 ,
608
617
},
609
618
{
610
619
name : "miss_on_difference_vary_headers" ,
@@ -632,6 +641,7 @@ func (s *HandlerIntegrationTestSuite) TestCachingVaries() {
632
641
"x-test" : "1" ,
633
642
},
634
643
},
644
+ executeAfter : time .Millisecond * 5 ,
635
645
},
636
646
{
637
647
name : "miss_on_difference_vary_cookies" ,
@@ -659,6 +669,7 @@ func (s *HandlerIntegrationTestSuite) TestCachingVaries() {
659
669
"x-test" : "1" ,
660
670
},
661
671
},
672
+ executeAfter : time .Millisecond * 5 ,
662
673
},
663
674
{
664
675
name : "miss_on_difference_vary_headers_cookies" ,
@@ -692,6 +703,7 @@ func (s *HandlerIntegrationTestSuite) TestCachingVaries() {
692
703
"x-test" : "2" ,
693
704
},
694
705
},
706
+ executeAfter : time .Millisecond * 5 ,
695
707
},
696
708
}
697
709
@@ -718,6 +730,8 @@ caching {
718
730
tester .InitServer (fmt .Sprintf (caddyfilePattern , config ), "caddyfile" )
719
731
720
732
for _ , testCase := range testCases {
733
+ <- time .After (testCase .executeAfter ) // wait for caching in background
734
+
721
735
r , _ := http .NewRequest (
722
736
"POST" ,
723
737
"http://localhost:9090/graphql" ,
@@ -944,14 +958,15 @@ caching {
944
958
body , _ := io .ReadAll (resp .Body )
945
959
resp .Body .Close ()
946
960
947
- s .Require ().Equal (string (body ), `{"data":{"users":[{"id":1,"name":"A"},{"id":2,"name":"B"},{"id":3,"name":"C"}]}}` , "unexpected response" )
961
+ s .Require ().Equalf (string (body ), `{"data":{"users":[{"id":1,"name":"A"},{"id":2,"name":"B"},{"id":3,"name":"C"}]}}` , "case %s: unexpected response" , testCase . name )
948
962
949
963
if i == 0 {
950
964
// always miss on first time.
951
- s .Require ().Equal (string (CachingStatusMiss ), resp .Header .Get ("x-cache" ), "cache status must MISS on first time" )
965
+ s .Require ().Equalf (string (CachingStatusMiss ), resp .Header .Get ("x-cache" ), "case %s: cache status must MISS on first time" , testCase . name )
952
966
} else {
953
- s .Require ().Equal (string (CachingStatusHit ), resp .Header .Get ("x-cache" ), "cache status must HIT on next time" )
954
- s .Require ().Equal (strconv .Itoa (i ), resp .Header .Get ("x-cache-hits" ), "hit times not equal" )
967
+ <- time .After (time .Millisecond * 5 ) // wait for caching in background
968
+ s .Require ().Equalf (string (CachingStatusHit ), resp .Header .Get ("x-cache" ), "case %s: cache status must HIT on next time" , testCase .name )
969
+ s .Require ().Equalf (strconv .Itoa (i ), resp .Header .Get ("x-cache-hits" ), "case %s: hit times not equal" , testCase .name )
955
970
}
956
971
}
957
972
@@ -980,7 +995,7 @@ func (s *HandlerIntegrationTestSuite) TestCachingControlRequestHeader() {
980
995
name string
981
996
cc string
982
997
expectedCachingStatus CachingStatus
983
- waitTime time.Duration
998
+ executeAfter time.Duration
984
999
}{
985
1000
{
986
1001
name : "first_time_cc_no_store" ,
@@ -1004,49 +1019,49 @@ func (s *HandlerIntegrationTestSuite) TestCachingControlRequestHeader() {
1004
1019
},
1005
1020
{
1006
1021
name : "max_age_with_valid_max_stale_cc_result_stale_still_hit" ,
1007
- waitTime : time .Millisecond * 50 ,
1022
+ executeAfter : time .Millisecond * 50 ,
1008
1023
cc : "max-age=1, max-stale=2" ,
1009
1024
expectedCachingStatus : CachingStatusHit ,
1010
1025
},
1011
1026
{
1012
1027
name : "max_age_with_empty_max_stale_cc_result_stale_still_hit" ,
1013
- waitTime : time .Millisecond * 50 ,
1028
+ executeAfter : time .Millisecond * 50 ,
1014
1029
cc : "max-age=1, max-stale" ,
1015
1030
expectedCachingStatus : CachingStatusHit ,
1016
1031
},
1017
1032
{
1018
1033
name : "max_age_with_invalid_max_stale_cc_result_stale_will_miss" ,
1019
- waitTime : time .Millisecond * 2050 ,
1034
+ executeAfter : time .Millisecond * 2050 ,
1020
1035
cc : "max-age=1, max-stale=1" ,
1021
1036
expectedCachingStatus : CachingStatusMiss ,
1022
1037
},
1023
1038
{
1024
1039
name : "max_age_without_max_stale_cc_result_stale_will_miss" ,
1025
- waitTime : time .Millisecond * 50 ,
1040
+ executeAfter : time .Millisecond * 50 ,
1026
1041
cc : "max-age=1" ,
1027
1042
expectedCachingStatus : CachingStatusMiss ,
1028
1043
},
1029
1044
{
1030
1045
name : "invalid_min_fresh_cc_will_miss" ,
1031
- waitTime : time .Second ,
1046
+ executeAfter : time .Second ,
1032
1047
cc : "min-fresh=1" ,
1033
1048
expectedCachingStatus : CachingStatusMiss ,
1034
1049
},
1035
1050
{
1036
1051
name : "invalid_max_stale_cc_will_miss" ,
1037
- waitTime : time .Millisecond * 1050 ,
1052
+ executeAfter : time .Millisecond * 1050 ,
1038
1053
cc : "max-stale=1" ,
1039
1054
expectedCachingStatus : CachingStatusMiss ,
1040
1055
},
1041
1056
{
1042
1057
name : "empty_max_stale_cc_will_hit" ,
1043
- waitTime : time .Millisecond * 55 ,
1058
+ executeAfter : time .Millisecond * 55 ,
1044
1059
cc : "max-stale" ,
1045
1060
expectedCachingStatus : CachingStatusHit ,
1046
1061
},
1047
1062
{
1048
1063
name : "valid_max_stale_cc_will_hit" ,
1049
- waitTime : time .Millisecond * 55 ,
1064
+ executeAfter : time .Millisecond * 55 ,
1050
1065
cc : "max-stale=1" ,
1051
1066
expectedCachingStatus : CachingStatusHit ,
1052
1067
},
@@ -1065,7 +1080,7 @@ caching {
1065
1080
` ), "caddyfile" )
1066
1081
1067
1082
for _ , testCase := range testCases {
1068
- <- time .After (testCase .waitTime )
1083
+ <- time .After (testCase .executeAfter ) // wait for caching in background
1069
1084
1070
1085
r , _ := http .NewRequest (
1071
1086
"POST" ,
0 commit comments