|
68 | 68 | end |
69 | 69 | end |
70 | 70 |
|
71 | | - # TODO: We currently don't support transaction propogation and hooks |
72 | | - # We'll want to fully implement this requirement once those are supported |
73 | 71 | specify "Requirement 3.2.3 - Evaluation context MUST be merged in the order: API (global; lowest precedence) -> transaction -> client -> invocation -> before hooks (highest precedence), with duplicate values being overwritten." do |
74 | 72 | api_context = OpenFeature::SDK::EvaluationContext.new(targeting_key: "api") |
| 73 | + transaction_context = OpenFeature::SDK::EvaluationContext.new("targeting_key" => "transaction", "transaction-related" => "field") |
75 | 74 | client_context = OpenFeature::SDK::EvaluationContext.new("targeting_key" => "client", "client-related" => "field") |
76 | 75 | invocation_context = OpenFeature::SDK::EvaluationContext.new("targeting_key" => "invocation", "invocation-related" => "field") |
77 | 76 |
|
78 | | - OpenFeature::SDK.configure { |c| c.evaluation_context = api_context } |
| 77 | + propagator = OpenFeature::SDK::ThreadLocalTransactionContextPropagator.new |
| 78 | + OpenFeature::SDK.configure do |c| |
| 79 | + c.evaluation_context = api_context |
| 80 | + c.transaction_context_propagator = propagator |
| 81 | + end |
| 82 | + propagator.set_transaction_context(transaction_context) |
| 83 | + |
79 | 84 | client = OpenFeature::SDK.build_client(evaluation_context: client_context) |
80 | 85 |
|
81 | | - expect_any_instance_of(OpenFeature::SDK::EvaluationContextBuilder).to receive(:call).with(api_context:, client_context:, invocation_context:).and_call_original |
| 86 | + expect_any_instance_of(OpenFeature::SDK::EvaluationContextBuilder).to receive(:call).with( |
| 87 | + api_context: api_context, |
| 88 | + transaction_context: transaction_context, |
| 89 | + client_context: client_context, |
| 90 | + invocation_context: invocation_context |
| 91 | + ).and_call_original |
82 | 92 |
|
83 | 93 | client.fetch_boolean_value(flag_key: "testing", default_value: true, evaluation_context: invocation_context) |
| 94 | + |
| 95 | + propagator.set_transaction_context(nil) |
| 96 | + end |
| 97 | + end |
| 98 | + |
| 99 | + context "3.3 Transaction Context Propagation" do |
| 100 | + after do |
| 101 | + OpenFeature::SDK.configure { |c| c.transaction_context_propagator = nil } |
| 102 | + end |
| 103 | + |
| 104 | + context "Requirement 3.3.1.1" do |
| 105 | + specify "The API SHOULD have a method for setting a transaction context propagator." do |
| 106 | + propagator = OpenFeature::SDK::ThreadLocalTransactionContextPropagator.new |
| 107 | + OpenFeature::SDK.set_transaction_context_propagator(propagator) |
| 108 | + |
| 109 | + expect(OpenFeature::SDK.configuration.transaction_context_propagator).to eq(propagator) |
| 110 | + end |
| 111 | + end |
| 112 | + |
| 113 | + context "Condition 3.3.1.2 - A transaction context propagator is configured." do |
| 114 | + let(:propagator) { OpenFeature::SDK::ThreadLocalTransactionContextPropagator.new } |
| 115 | + |
| 116 | + before do |
| 117 | + OpenFeature::SDK.set_transaction_context_propagator(propagator) |
| 118 | + end |
| 119 | + |
| 120 | + context "Conditional Requirement 3.3.1.2.1" do |
| 121 | + specify "The API MUST have a method for setting the evaluation context of the transaction context propagator for the current transaction." do |
| 122 | + context = OpenFeature::SDK::EvaluationContext.new(targeting_key: "txn-user") |
| 123 | + OpenFeature::SDK.set_transaction_context(context) |
| 124 | + |
| 125 | + expect(propagator.get_transaction_context).to eq(context) |
| 126 | + |
| 127 | + propagator.set_transaction_context(nil) |
| 128 | + end |
| 129 | + end |
| 130 | + end |
| 131 | + |
| 132 | + context "Requirement 3.3.1.2.2" do |
| 133 | + specify "A transaction context propagator MUST have a method for setting the evaluation context of the current transaction." do |
| 134 | + propagator = OpenFeature::SDK::ThreadLocalTransactionContextPropagator.new |
| 135 | + context = OpenFeature::SDK::EvaluationContext.new(targeting_key: "txn-user") |
| 136 | + |
| 137 | + propagator.set_transaction_context(context) |
| 138 | + |
| 139 | + expect(propagator.get_transaction_context).to eq(context) |
| 140 | + |
| 141 | + propagator.set_transaction_context(nil) |
| 142 | + end |
| 143 | + end |
| 144 | + |
| 145 | + context "Requirement 3.3.1.2.3" do |
| 146 | + specify "A transaction context propagator MUST have a method for getting the evaluation context of the current transaction." do |
| 147 | + propagator = OpenFeature::SDK::ThreadLocalTransactionContextPropagator.new |
| 148 | + |
| 149 | + expect(propagator.get_transaction_context).to be_nil |
| 150 | + |
| 151 | + context = OpenFeature::SDK::EvaluationContext.new(targeting_key: "txn-user") |
| 152 | + propagator.set_transaction_context(context) |
| 153 | + |
| 154 | + expect(propagator.get_transaction_context).to eq(context) |
| 155 | + |
| 156 | + propagator.set_transaction_context(nil) |
| 157 | + end |
84 | 158 | end |
85 | 159 | end |
86 | 160 | end |
0 commit comments