@@ -717,7 +717,8 @@ extension DefaultCmabServiceTests {
717717 }
718718
719719 func testCacheTimeoutZero( ) {
720- // Create a cache with timeout 0 (immediate expiration)
720+ // When timeout is 0, LruCache uses default timeout (30 * 60 seconds = 1800 seconds)
721+ // So cache will NOT expire within the test timeframe
721722 let zeroTimeoutCache = CmabCache ( size: 10 , timeoutInSecs: 0 )
722723 let zeroTimeoutService = DefaultCmabService ( cmabClient: cmabClient, cmabCache: zeroTimeoutCache)
723724
@@ -733,48 +734,49 @@ extension DefaultCmabServiceTests {
733734 options: [ ]
734735 ) { result in
735736 switch result {
736- case . success( let decision) :
737- XCTAssertEqual ( decision. variationId, " variation-first " )
738- XCTAssertTrue ( self . cmabClient. fetchDecisionCalled, " Should call API on first request " )
739-
740- case . failure( let error) :
741- XCTFail ( " Expected success but got error: \( error) " )
737+ case . success( let decision) :
738+ XCTAssertEqual ( decision. variationId, " variation-first " )
739+ XCTAssertTrue ( self . cmabClient. fetchDecisionCalled, " Should call API on first request " )
740+
741+ case . failure( let error) :
742+ XCTFail ( " Expected success but got error: \( error) " )
742743 }
743744 expectation1. fulfill ( )
744745 }
745746
746747 wait ( for: [ expectation1] , timeout: 1.0 )
747748
748- // Reset and change the variation
749+ // Reset client but don't change the result
749750 cmabClient. reset ( )
750751 cmabClient. fetchDecisionResult = . success( " variation-second " )
751752
752- // Small delay to ensure cache timeout
753- Thread . sleep ( forTimeInterval: 1 .1)
753+ // Small delay (but not enough to expire default 1800s timeout)
754+ Thread . sleep ( forTimeInterval: 0 .1)
754755
755756 let expectation2 = self . expectation ( description: " second request " )
756757
757- // Second request - should NOT use cache (timeout = 0, cache expired)
758+ // Second request - SHOULD use cache (timeout defaults to 1800s, not expired)
758759 zeroTimeoutService. getDecision (
759760 config: config,
760761 userContext: userContext,
761762 ruleId: " exp-123 " ,
762763 options: [ ]
763764 ) { result in
764765 switch result {
765- case . success( let decision) :
766- XCTAssertEqual ( decision. variationId, " variation-second " )
767- XCTAssertTrue ( self . cmabClient. fetchDecisionCalled, " Should call API again when cache timeout is 0 " )
768-
769- case . failure( let error) :
770- XCTFail ( " Expected success but got error: \( error) " )
766+ case . success( let decision) :
767+ // Should get cached value, not the new one
768+ XCTAssertEqual ( decision. variationId, " variation-first " )
769+ XCTAssertFalse ( self . cmabClient. fetchDecisionCalled, " Should use cache when timeout defaults to 1800s " )
770+
771+ case . failure( let error) :
772+ XCTFail ( " Expected success but got error: \( error) " )
771773 }
772774 expectation2. fulfill ( )
773775 }
774776
775777 wait ( for: [ expectation2] , timeout: 1.0 )
776778 }
777-
779+
778780 func testCacheSizeZeroAndTimeoutZero( ) {
779781 // Create a cache with both size 0 and timeout 0 (completely disabled)
780782 let disabledCache = CmabCache ( size: 0 , timeoutInSecs: 0 )
0 commit comments