|
158 | 158 | ) |
159 | 159 | end |
160 | 160 |
|
161 | | - it "raises ConfigurationError when Float::INFINITY" do |
162 | | - config.cache_ttl = Float::INFINITY |
163 | | - expect { config.validate! }.to raise_error( |
164 | | - Langfuse::ConfigurationError, |
165 | | - "cache_ttl cannot be Float::INFINITY" |
166 | | - ) |
167 | | - end |
168 | | - |
169 | 161 | it "allows zero (disabled cache)" do |
170 | 162 | config.cache_ttl = 0 |
171 | 163 | expect { config.validate! }.not_to raise_error |
|
228 | 220 | config.cache_stale_ttl = -1 |
229 | 221 | expect { config.validate! }.to raise_error( |
230 | 222 | Langfuse::ConfigurationError, |
231 | | - "cache_stale_ttl must be non-negative" |
| 223 | + "cache_stale_ttl must be non-negative or :indefinite" |
232 | 224 | ) |
233 | 225 | end |
234 | 226 |
|
235 | 227 | it "raises ConfigurationError when nil" do |
236 | 228 | config.cache_stale_ttl = nil |
237 | 229 | expect { config.validate! }.to raise_error( |
238 | 230 | Langfuse::ConfigurationError, |
239 | | - "cache_stale_ttl must be non-negative" |
| 231 | + "cache_stale_ttl must be non-negative or :indefinite" |
240 | 232 | ) |
241 | 233 | end |
242 | 234 |
|
|
249 | 241 | config.cache_stale_ttl = 300 |
250 | 242 | expect { config.validate! }.not_to raise_error |
251 | 243 | end |
| 244 | + |
| 245 | + it "allows :indefinite symbol" do |
| 246 | + config.cache_stale_ttl = :indefinite |
| 247 | + expect { config.validate! }.not_to raise_error |
| 248 | + end |
252 | 249 | end |
253 | 250 |
|
254 | 251 | context "when cache_refresh_threads is invalid" do |
|
363 | 360 | expect(config.cache_stale_ttl).to eq(600) |
364 | 361 | end |
365 | 362 |
|
| 363 | + it "allows setting cache_stale_ttl to :indefinite" do |
| 364 | + config.cache_stale_ttl = :indefinite |
| 365 | + expect(config.cache_stale_ttl).to eq(:indefinite) |
| 366 | + end |
| 367 | + |
366 | 368 | it "allows setting cache_refresh_threads" do |
367 | 369 | config.cache_refresh_threads = 10 |
368 | 370 | expect(config.cache_refresh_threads).to eq(10) |
|
443 | 445 | expect(Langfuse::Config::DEFAULT_CACHE_REFRESH_THREADS).to eq(5) |
444 | 446 | end |
445 | 447 | end |
| 448 | + |
| 449 | + describe "#normalized_stale_ttl" do |
| 450 | + let(:config) do |
| 451 | + described_class.new do |c| |
| 452 | + c.public_key = "pk_test" |
| 453 | + c.secret_key = "sk_test" |
| 454 | + end |
| 455 | + end |
| 456 | + |
| 457 | + it "returns the numeric value unchanged for regular TTL" do |
| 458 | + config.cache_stale_ttl = 300 |
| 459 | + expect(config.normalized_stale_ttl).to eq(300) |
| 460 | + end |
| 461 | + |
| 462 | + it "returns 0 for zero TTL" do |
| 463 | + config.cache_stale_ttl = 0 |
| 464 | + expect(config.normalized_stale_ttl).to eq(0) |
| 465 | + end |
| 466 | + |
| 467 | + it "returns INDEFINITE_SECONDS when cache_stale_ttl is :indefinite" do |
| 468 | + config.cache_stale_ttl = :indefinite |
| 469 | + expect(config.normalized_stale_ttl).to eq(Langfuse::Config::INDEFINITE_SECONDS) |
| 470 | + end |
| 471 | + |
| 472 | + it "does not mutate the original cache_stale_ttl value" do |
| 473 | + config.cache_stale_ttl = :indefinite |
| 474 | + config.normalized_stale_ttl # Call normalization |
| 475 | + expect(config.cache_stale_ttl).to eq(:indefinite) # Original value preserved |
| 476 | + end |
| 477 | + |
| 478 | + it "works with SWR auto-configuration" do |
| 479 | + config_swr = described_class.new do |c| |
| 480 | + c.public_key = "pk_test" |
| 481 | + c.secret_key = "sk_test" |
| 482 | + c.cache_ttl = 120 |
| 483 | + c.cache_stale_while_revalidate = true |
| 484 | + c.cache_stale_ttl = :indefinite |
| 485 | + end |
| 486 | + |
| 487 | + expect(config_swr.cache_stale_ttl).to eq(:indefinite) |
| 488 | + expect(config_swr.normalized_stale_ttl).to eq(Langfuse::Config::INDEFINITE_SECONDS) |
| 489 | + end |
| 490 | + end |
446 | 491 | end |
0 commit comments