|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe "ALWAYS_SAVE_AFTER_REQUEST" do |
| 4 | + |
| 5 | + before :each do |
| 6 | + get("#{SETTINGS_PATH}/sessionPersistPolicies") |
| 7 | + @oldSessionPersistPoliciesValue = json['value'] |
| 8 | + enums = @oldSessionPersistPoliciesValue.split(',') |
| 9 | + enums << 'ALWAYS_SAVE_AFTER_REQUEST' |
| 10 | + post("#{SETTINGS_PATH}/sessionPersistPolicies", body: {value: enums.join(',')}) |
| 11 | + end |
| 12 | + |
| 13 | + after :each do |
| 14 | + post("#{SETTINGS_PATH}/sessionPersistPolicies", body: {value: @oldSessionPersistPoliciesValue}) |
| 15 | + end |
| 16 | + |
| 17 | + it 'should optionally support persisting the session after every request regardless of changed status' do |
| 18 | + post(SESSION_PATH, body: {param2: '5'}) |
| 19 | + get("#{SESSION_ATTRIBUTES_PATH}/param2") |
| 20 | + json['value'].should == '5' |
| 21 | + |
| 22 | + # This is not a perfect guarantee, but in general we're assuming |
| 23 | + # that the requests will happen in the following order: |
| 24 | + # - Post(value=5) starts |
| 25 | + # - Post(value=6) starts |
| 26 | + # - Post(value=6) finishes |
| 27 | + # - Get() returns 6 |
| 28 | + # - Post(value=5) finishes |
| 29 | + # - Get() returns 5 (because the change value=5 saved on request finish even though it wasn't a change) |
| 30 | + long_request = Thread.new do |
| 31 | + post("#{SESSION_ATTRIBUTES_PATH}/param2", body: {value: '5', sleep: 2000}) |
| 32 | + end |
| 33 | + |
| 34 | + sleep 0.5 |
| 35 | + get("#{SESSION_ATTRIBUTES_PATH}/param2") |
| 36 | + json['value'].should == '5' |
| 37 | + |
| 38 | + post("#{SESSION_ATTRIBUTES_PATH}/param2", body: {value: '6'}) |
| 39 | + get("#{SESSION_ATTRIBUTES_PATH}/param2") |
| 40 | + json['value'].should == '6' |
| 41 | + |
| 42 | + long_request.join |
| 43 | + |
| 44 | + get("#{SESSION_ATTRIBUTES_PATH}/param2") |
| 45 | + json['value'].should == '5' |
| 46 | + end |
| 47 | +end |
0 commit comments