Skip to content

Commit 73e247f

Browse files
committed
Split out spec tests into separate files.
1 parent ace856d commit 73e247f

File tree

6 files changed

+208
-209
lines changed

6 files changed

+208
-209
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
require 'spec_helper'
2+
3+
describe "SAVE_ON_CHANGE" do
4+
5+
before :each do
6+
get("#{SETTINGS_PATH}/sessionPersistPolicies")
7+
@oldSessionPersistPoliciesValue = json['value']
8+
enums = @oldSessionPersistPoliciesValue.split(',')
9+
enums << 'SAVE_ON_CHANGE'
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 support persisting the session on change to minimize race conditions on simultaneous updates' 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 6 (because the change value=5 saved immediately rather than on request finish)
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 == '6'
46+
end
47+
end
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require 'spec_helper'
2+
3+
describe 'session creation' do
4+
5+
it 'should begin without a session' do
6+
get(SESSION_PATH)
7+
json.should_not have_key('sessionId')
8+
end
9+
10+
it 'should generate a session ID' do
11+
post(SESSION_PATH)
12+
json.should have_key('sessionId')
13+
end
14+
15+
it 'should not create a session when requesting session creation with existing session ID' do
16+
pending
17+
end
18+
19+
it 'should detect a session ID collision and generate a new session ID' do
20+
pending
21+
end
22+
23+
it 'should detect and report race conditions when creating new sessions' do
24+
pending
25+
end
26+
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require 'spec_helper'
2+
3+
describe 'session expiration' do
4+
5+
before :each do
6+
get("#{SETTINGS_PATH}/maxInactiveInterval")
7+
@oldMaxInactiveIntervalValue = json['value']
8+
post("#{SETTINGS_PATH}/maxInactiveInterval", body: {value: '1'})
9+
end
10+
11+
after :each do
12+
post("#{SETTINGS_PATH}/maxInactiveInterval", body: {value: @oldMaxInactiveIntervalValue})
13+
end
14+
15+
it 'should no longer contain a session after the expiration timeout has passed' do
16+
post(SESSION_PATH)
17+
created_session_id = json['sessionId']
18+
get(SESSION_PATH)
19+
json['sessionId'].should == created_session_id
20+
sleep 1.0
21+
get(SESSION_PATH)
22+
json['sessionId'].should be_nil
23+
end
24+
end
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
require 'spec_helper'
2+
3+
describe 'session updating' do
4+
it 'should support setting a value in the session' do
5+
post(SESSION_PATH, body: {param1: '5'})
6+
json['attributes'].should have_key('param1')
7+
json['attributes']['param1'].should == '5'
8+
end
9+
10+
it 'should support updating a value in the session' do
11+
post(SESSION_PATH, body: {param1: '5'})
12+
json['attributes'].should have_key('param1')
13+
json['attributes']['param1'].should == '5'
14+
15+
put(SESSION_PATH, query: {param1: '6'})
16+
json['attributes']['param1'].should == '6'
17+
end
18+
19+
it 'should support setting a complex values in the session' do
20+
post(SESSION_PATH, body: {param1: {subparam: '5'}})
21+
json['attributes']['param1'].should have_key('subparam')
22+
json['attributes']['param1']['subparam'].should == '5'
23+
end
24+
25+
it 'should persist session attributes between requests' do
26+
post(SESSION_PATH, body: {param1: '5'})
27+
get(SESSION_PATH)
28+
json['attributes']['param1'].should == '5'
29+
end
30+
31+
it 'should persist updated session attributes between requests' do
32+
post(SESSION_PATH, body: {param1: '5'})
33+
put(SESSION_PATH, query: {param1: '6'})
34+
get(SESSION_PATH)
35+
json['attributes']['param1'].should == '6'
36+
end
37+
38+
it 'should support removing a value in the session' do
39+
post("#{SESSION_ATTRIBUTES_PATH}/param1", body: {value: '5'})
40+
get(SESSION_ATTRIBUTES_PATH)
41+
json['keys'].should include('param1')
42+
43+
delete("#{SESSION_ATTRIBUTES_PATH}/param1")
44+
get(SESSION_ATTRIBUTES_PATH)
45+
json['keys'].should_not include('param1')
46+
end
47+
48+
it 'should only update if the session changes' do
49+
post(SESSION_PATH, body: {param1: '5'})
50+
51+
# This is not a perfect guarantee, but in general we're assuming
52+
# that the requests will happen in the following order:
53+
# - Post(value=5) starts
54+
# - Post(value=6) starts
55+
# - Post(value=6) finishes
56+
# - Get() returns 6
57+
# - Post(value=5) finishes
58+
# Note: this would represent a change from the current persisted value
59+
# but it does not represent a change from when this request's
60+
# copy of the session was loaded, so it shouldn't be persisted.
61+
# - Get() returns 6
62+
last_request_to_finish = Thread.new do
63+
post("#{SESSION_ATTRIBUTES_PATH}/param1", body: {value: '5', sleep: 2000})
64+
end
65+
sleep 1
66+
post("#{SESSION_ATTRIBUTES_PATH}/param1", body: {value: '6'})
67+
# Verify our assumption that this request loaded it's session
68+
# before the request Post(value=7) finished.
69+
json['oldValue'].should == '5'
70+
get("#{SESSION_ATTRIBUTES_PATH}/param1")
71+
json['value'].should == '6'
72+
73+
last_request_to_finish.join
74+
75+
get("#{SESSION_ATTRIBUTES_PATH}/param1")
76+
json['value'].should == '6'
77+
end
78+
79+
it 'should default to last-write-wins behavior for simultaneous updates' do
80+
post(SESSION_PATH, body: {param1: '5'})
81+
82+
# This is not a perfect guarantee, but in general we're assuming
83+
# that the requests will happen in the following order:
84+
# - Post(value=7) starts
85+
# - Post(value=6) starts
86+
# - Post(value=6) finishes
87+
# - Get() returns 6
88+
# - Post(value=7) finishes
89+
# - Get() returns 7
90+
winner = Thread.new do
91+
post("#{SESSION_ATTRIBUTES_PATH}/param1", body: {value: '7', sleep: 2000})
92+
end
93+
sleep 1
94+
post("#{SESSION_ATTRIBUTES_PATH}/param1", body: {value: '6'})
95+
# Verify our assumption that this request loaded it's session
96+
# before the request Post(value=7) finished.
97+
json['oldValue'].should == '5'
98+
get("#{SESSION_ATTRIBUTES_PATH}/param1")
99+
json['value'].should == '6'
100+
101+
winner.join
102+
103+
get("#{SESSION_ATTRIBUTES_PATH}/param1")
104+
json['value'].should == '7'
105+
end
106+
end

0 commit comments

Comments
 (0)