Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
e75f7e58
Commit
e75f7e58
authored
11 years ago
by
Vincent Petry
Browse files
Options
Downloads
Patches
Plain Diff
Added unit tests for session_keepalive / heartbeat
parent
912da8d2
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/js/tests/specHelper.js
+17
-1
17 additions, 1 deletion
core/js/tests/specHelper.js
core/js/tests/specs/coreSpec.js
+74
-0
74 additions, 0 deletions
core/js/tests/specs/coreSpec.js
with
91 additions
and
1 deletion
core/js/tests/specHelper.js
+
17
−
1
View file @
e75f7e58
...
...
@@ -19,6 +19,8 @@
*
*/
/* global OC */
/**
* Simulate the variables that are normally set by PHP code
*/
...
...
@@ -57,10 +59,15 @@ window.oc_webroot = location.href + '/';
window
.
oc_appswebroots
=
{
"
files
"
:
window
.
oc_webroot
+
'
/apps/files/
'
};
window
.
oc_config
=
{
session_lifetime
:
600
*
1000
,
session_keepalive
:
false
};
// global setup for all tests
(
function
setupTests
()
{
var
fakeServer
=
null
;
var
fakeServer
=
null
,
routesRequestStub
;
beforeEach
(
function
()
{
// enforce fake XHR, tests should not depend on the server and
...
...
@@ -78,9 +85,18 @@ window.oc_appswebroots = {
// make it globally available, so that other tests can define
// custom responses
window
.
fakeServer
=
fakeServer
;
OC
.
Router
.
routes
=
[];
OC
.
Router
.
routes_request
=
{
state
:
sinon
.
stub
().
returns
(
'
resolved
'
),
done
:
sinon
.
stub
()
};
});
afterEach
(
function
()
{
OC
.
Router
.
routes_request
.
state
.
reset
();
OC
.
Router
.
routes_request
.
done
.
reset
();
// uncomment this to log requests
// console.log(window.fakeServer.requests);
fakeServer
.
restore
();
...
...
This diff is collapsed.
Click to expand it.
core/js/tests/specs/coreSpec.js
+
74
−
0
View file @
e75f7e58
...
...
@@ -104,4 +104,78 @@ describe('Core base tests', function() {
})).
toEqual
(
'
number=123
'
);
});
});
describe
(
'
Session heartbeat
'
,
function
()
{
var
clock
,
oldConfig
,
loadedStub
,
routeStub
,
counter
;
beforeEach
(
function
()
{
clock
=
sinon
.
useFakeTimers
();
oldConfig
=
window
.
oc_config
;
loadedStub
=
sinon
.
stub
(
OC
.
Router
,
'
registerLoadedCallback
'
);
routeStub
=
sinon
.
stub
(
OC
.
Router
,
'
generate
'
).
returns
(
'
/heartbeat
'
);
counter
=
0
;
fakeServer
.
autoRespond
=
true
;
fakeServer
.
autoRespondAfter
=
0
;
fakeServer
.
respondWith
(
/
\/
heartbeat/
,
function
(
xhr
)
{
counter
++
;
xhr
.
respond
(
200
,
{
'
Content-Type
'
:
'
application/json
'
},
'
{}
'
);
});
});
afterEach
(
function
()
{
clock
.
restore
();
window
.
oc_config
=
oldConfig
;
loadedStub
.
restore
();
routeStub
.
restore
();
});
it
(
'
sends heartbeat half the session lifetime when heartbeat enabled
'
,
function
()
{
window
.
oc_config
=
{
session_keepalive
:
true
,
session_lifetime
:
300
};
window
.
initCore
();
expect
(
loadedStub
.
calledOnce
).
toEqual
(
true
);
loadedStub
.
yield
();
expect
(
routeStub
.
calledWith
(
'
heartbeat
'
)).
toEqual
(
true
);
expect
(
counter
).
toEqual
(
0
);
// less than half, still nothing
clock
.
tick
(
100
*
1000
);
expect
(
counter
).
toEqual
(
0
);
// reach past half (160), one call
clock
.
tick
(
55
*
1000
);
expect
(
counter
).
toEqual
(
1
);
// almost there to the next, still one
clock
.
tick
(
140
*
1000
);
expect
(
counter
).
toEqual
(
1
);
// past it, second call
clock
.
tick
(
20
*
1000
);
expect
(
counter
).
toEqual
(
2
);
});
it
(
'
does no send heartbeat when heartbeat disabled
'
,
function
()
{
window
.
oc_config
=
{
session_keepalive
:
false
,
session_lifetime
:
300
};
window
.
initCore
();
expect
(
loadedStub
.
notCalled
).
toEqual
(
true
);
expect
(
routeStub
.
notCalled
).
toEqual
(
true
);
expect
(
counter
).
toEqual
(
0
);
clock
.
tick
(
1000000
);
// still nothing
expect
(
counter
).
toEqual
(
0
);
});
});
});
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment