|
1443 | 1443 | expect(client_old_spec.get_treatment('whitelisted_user', 'whitelist_feature')).to eq('control') |
1444 | 1444 | end |
1445 | 1445 | end |
| 1446 | + |
| 1447 | + context 'fallback treatments' do |
| 1448 | + it 'feature not found' do |
| 1449 | + splits_fallback = File.read(File.join(SplitIoClient.root, 'spec/test_data/splits/imp-toggle.json')) |
| 1450 | + stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.3&since=-1&rbSince=-1') |
| 1451 | + .to_return(status: 200, body: splits_fallback) |
| 1452 | + factory_fallback = |
| 1453 | + SplitIoClient::SplitFactory.new('test_api_key', |
| 1454 | + fallback_treatments: SplitIoClient::Engine::Models::FallbackTreatmentsConfiguration.new( |
| 1455 | + SplitIoClient::Engine::Models::FallbackTreatment.new( |
| 1456 | + "on-global", '{"prop": "global"}' |
| 1457 | + ), |
| 1458 | + {:feature => SplitIoClient::Engine::Models::FallbackTreatment.new( |
| 1459 | + "on-local", '{"prop": "local"}' |
| 1460 | + ) |
| 1461 | + } |
| 1462 | + ), |
| 1463 | + impressions_mode: :optimized, |
| 1464 | + features_refresh_rate: 9999, |
| 1465 | + telemetry_refresh_rate: 99999, |
| 1466 | + impressions_refresh_rate: 99999, |
| 1467 | + streaming_enabled: false |
| 1468 | + ) |
| 1469 | + |
| 1470 | + client_fallback = factory_fallback.client |
| 1471 | + client_fallback.block_until_ready |
| 1472 | + result = client_fallback.get_treatment_with_config('key2', 'feature') |
| 1473 | + expect(result[:treatment]).to eq('on-local') |
| 1474 | + expect(result[:config]).to eq('{"prop": "local"}') |
| 1475 | + |
| 1476 | + result = client_fallback.get_treatment_with_config('key3', 'feature2') |
| 1477 | + expect(result[:treatment]).to eq('on-global') |
| 1478 | + expect(result[:config]).to eq('{"prop": "global"}') |
| 1479 | + |
| 1480 | + impressions_repository = client_fallback.instance_variable_get(:@impressions_repository) |
| 1481 | + imps = impressions_repository.batch |
| 1482 | + expect(imps.length()).to eq(0) |
| 1483 | + end |
| 1484 | + |
| 1485 | + it 'exception' do |
| 1486 | + splits_fallback = File.read(File.join(SplitIoClient.root, 'spec/test_data/splits/imp-toggle.json')) |
| 1487 | + stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.3&since=-1&rbSince=-1') |
| 1488 | + .to_return(status: 200, body: splits_fallback) |
| 1489 | + factory_fallback = |
| 1490 | + SplitIoClient::SplitFactory.new('test_api_key', |
| 1491 | + fallback_treatments: SplitIoClient::Engine::Models::FallbackTreatmentsConfiguration.new( |
| 1492 | + SplitIoClient::Engine::Models::FallbackTreatment.new( |
| 1493 | + "on-global", '{"prop": "global"}' |
| 1494 | + ), |
| 1495 | + {:feature => SplitIoClient::Engine::Models::FallbackTreatment.new( |
| 1496 | + "on-local", '{"prop": "local"}' |
| 1497 | + ) |
| 1498 | + } |
| 1499 | + ), |
| 1500 | + impressions_mode: :optimized, |
| 1501 | + features_refresh_rate: 9999, |
| 1502 | + telemetry_refresh_rate: 99999, |
| 1503 | + impressions_refresh_rate: 99999, |
| 1504 | + streaming_enabled: false |
| 1505 | + ) |
| 1506 | + |
| 1507 | + client_fallback = factory_fallback.client |
| 1508 | + client_fallback.block_until_ready |
| 1509 | + |
| 1510 | + splits_repository = client_fallback.instance_variable_get(:@splits_repository) |
| 1511 | + splits = File.read(File.join(SplitIoClient.root, 'spec/test_data/splits/imp-toggle.json')) |
| 1512 | + split = JSON.parse(splits,:symbolize_names => true)[:ff][:d][0] |
| 1513 | + split[:trafficAllocation] = nil |
| 1514 | + splits_repository.update([split], [], -1) |
| 1515 | + |
| 1516 | + result = client_fallback.get_treatment_with_config('key3', 'with_track_disabled') |
| 1517 | + expect(result[:treatment]).to eq('on-global') |
| 1518 | + expect(result[:config]).to eq('{"prop": "global"}') |
| 1519 | + |
| 1520 | + impressions_repository = client_fallback.instance_variable_get(:@impressions_repository) |
| 1521 | + imps = impressions_repository.batch |
| 1522 | + expect(imps.length()).to eq(1) |
| 1523 | + expect(imps[0][:i][:f]).to eq('with_track_disabled') |
| 1524 | + expect(imps[0][:i][:r]).to eq('fallback - exception') |
| 1525 | + end |
| 1526 | + |
| 1527 | + it 'client not ready' do |
| 1528 | + splits_fallback = File.read(File.join(SplitIoClient.root, 'spec/test_data/splits/imp-toggle.json')) |
| 1529 | + stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.3&since=-1&rbSince=-1') |
| 1530 | + .to_return(status: 200, body: splits_fallback) |
| 1531 | + factory_fallback = |
| 1532 | + SplitIoClient::SplitFactory.new('test_api_key', |
| 1533 | + fallback_treatments: SplitIoClient::Engine::Models::FallbackTreatmentsConfiguration.new( |
| 1534 | + SplitIoClient::Engine::Models::FallbackTreatment.new( |
| 1535 | + "on-global", '{"prop": "global"}' |
| 1536 | + ), |
| 1537 | + {:feature => SplitIoClient::Engine::Models::FallbackTreatment.new( |
| 1538 | + "on-local", '{"prop": "local"}' |
| 1539 | + ) |
| 1540 | + } |
| 1541 | + ), |
| 1542 | + impressions_mode: :optimized, |
| 1543 | + features_refresh_rate: 9999, |
| 1544 | + telemetry_refresh_rate: 99999, |
| 1545 | + impressions_refresh_rate: 99999, |
| 1546 | + streaming_enabled: false |
| 1547 | + ) |
| 1548 | + |
| 1549 | + client_fallback = factory_fallback.client |
| 1550 | + |
| 1551 | + result = client_fallback.get_treatment_with_config('key3', 'with_track_disabled') |
| 1552 | + expect(result[:treatment]).to eq('on-global') |
| 1553 | + expect(result[:config]).to eq('{"prop": "global"}') |
| 1554 | + |
| 1555 | + impressions_repository = client_fallback.instance_variable_get(:@impressions_repository) |
| 1556 | + imps = impressions_repository.batch |
| 1557 | + expect(imps.length()).to eq(1) |
| 1558 | + expect(imps[0][:i][:f]).to eq('with_track_disabled') |
| 1559 | + expect(imps[0][:i][:r]).to eq('fallback - not ready') |
| 1560 | + end |
| 1561 | + end |
1446 | 1562 | end |
1447 | 1563 |
|
1448 | 1564 | private |
|
0 commit comments