@@ -75,15 +75,6 @@ func TestMultipleRetrieversWithOverrideFlag(t *testing.T) {
75
75
assert .NotEqual (t , flag .ErrorCodeFlagNotFound , flagRes2 .ErrorCode )
76
76
}
77
77
78
- func TestStartWithNegativeInterval (t * testing.T ) {
79
- _ , err := ffclient .New (ffclient.Config {
80
- PollingInterval : - 60 * time .Second ,
81
- Retriever : & fileretriever.Retriever {Path : "testdata/flag-config.yaml" },
82
- LeveledLogger : slog .Default (),
83
- })
84
- assert .Error (t , err )
85
- }
86
-
87
78
func TestStartWithMinInterval (t * testing.T ) {
88
79
_ , err := ffclient .New (ffclient.Config {
89
80
PollingInterval : 2 ,
@@ -743,3 +734,39 @@ func Test_DisableNotifierOnInit(t *testing.T) {
743
734
})
744
735
}
745
736
}
737
+
738
+ func TestStartWithNegativeIntervalToDisablePolling (t * testing.T ) {
739
+ content , err := os .ReadFile ("testdata/flag-config.yaml" )
740
+ assert .NoError (t , err )
741
+
742
+ // copy of the file
743
+ tempFile , err := os .CreateTemp ("" , "" )
744
+ assert .NoError (t , err )
745
+ defer func () { _ = os .Remove (tempFile .Name ()) }()
746
+ err = os .WriteFile (tempFile .Name (), content , os .ModePerm )
747
+ assert .NoError (t , err )
748
+
749
+ goff , err := ffclient .New (ffclient.Config {
750
+ PollingInterval : - 1 * time .Second ,
751
+ Retriever : & fileretriever.Retriever {Path : tempFile .Name ()},
752
+ LeveledLogger : slog .Default (),
753
+ })
754
+ assert .NoError (t , err )
755
+
756
+ cacheRefresh := goff .GetCacheRefreshDate ()
757
+
758
+ // modify the file to trigger a refresh
759
+ newContent , err := os .ReadFile ("testdata/flag-config-2nd-file.yaml" )
760
+ assert .NoError (t , err )
761
+ err = os .WriteFile (tempFile .Name (), newContent , os .ModePerm )
762
+ assert .NoError (t , err )
763
+
764
+ // wait to be sure we give time to the goroutine to refresh the cache
765
+ time .Sleep (2 * time .Second )
766
+
767
+ assert .Equal (t , cacheRefresh , goff .GetCacheRefreshDate ())
768
+
769
+ // we force a refresh to check if the cache is refreshed
770
+ goff .ForceRefresh ()
771
+ assert .NotEqual (t , cacheRefresh , goff .GetCacheRefreshDate ())
772
+ }
0 commit comments