Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio-main
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Hardik Juneja
jio-main
Commits
cb071f1a
Commit
cb071f1a
authored
Sep 27, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jio tests updated
parent
3e152964
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
578 additions
and
524 deletions
+578
-524
test/jio/tests.js
test/jio/tests.js
+572
-519
test/jio/util.js
test/jio/util.js
+4
-3
test/tests.html
test/tests.html
+1
-1
test/tests.require.js
test/tests.require.js
+1
-1
No files found.
test/jio/tests.js
View file @
cb071f1a
/*jslint indent: 2, maxlen: 80, nomen: true */
/*jslint indent: 2, maxlen: 80, nomen: true */
/*global define, window, exports, require, jIO, fake_storage, ok, module, test,
/*global define, window, exports, require, jIO, fake_storage, ok, module, test,
expect, deepEqual, FileReader, Blob, setTimeout, localStorage */
stop, start, deepEqual, FileReader, Blob, setTimeout, clearTimeout,
localStorage */
(
function
(
dependencies
,
module
)
{
(
function
(
dependencies
,
module
)
{
"
use strict
"
;
"
use strict
"
;
...
@@ -13,31 +14,23 @@
...
@@ -13,31 +14,23 @@
module
(
fake_storage
,
jIO
);
module
(
fake_storage
,
jIO
);
}([
'
fakestorage
'
,
'
jio
'
,
'
sinon_qunit
'
],
function
(
fake_storage
,
jIO
)
{
}([
'
fakestorage
'
,
'
jio
'
,
'
sinon_qunit
'
],
function
(
fake_storage
,
jIO
)
{
"
use strict
"
;
"
use strict
"
;
var
JIO
=
jIO
.
JIO
,
commands
=
fake_storage
.
commands
;
var
test_name
,
JIO
=
jIO
.
JIO
,
commands
=
fake_storage
.
commands
;
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// Tests
// Tests
module
(
'
JIO
'
);
module
(
'
JIO
'
);
/**
test
(
'
should initialize itself without error
'
,
1
,
function
()
{
* Tests the instance initialization
var
jio
=
new
JIO
(
undefined
,
{
*/
"
workspace
"
:
{}
test
(
'
Init
'
,
function
()
{
expect
(
1
);
var
workspace
=
{},
jio
=
new
JIO
(
undefined
,
{
"
workspace
"
:
workspace
});
});
// tests if jio is an object
// tests if jio is an object
ok
(
typeof
jio
===
'
object
'
,
'
Init ok!
'
);
ok
(
typeof
jio
===
'
object
'
,
'
instance is an object
'
);
});
});
/**
test
(
'
should throw error when giving no parameter to `post`
'
,
1
,
function
()
{
* Tests a wrong command
*/
test
(
'
Wrong parameters
'
,
function
()
{
expect
(
2
);
var
result
,
jio
=
new
JIO
({
var
result
,
jio
=
new
JIO
({
"
type
"
:
"
fake
"
,
"
type
"
:
"
fake
"
,
"
id
"
:
"
Wrong para
"
"
id
"
:
"
Wrong para
"
...
@@ -56,6 +49,16 @@
...
@@ -56,6 +49,16 @@
"
TypeError: JIO().post(): Argument 1 is not of type 'object'
"
,
"
TypeError: JIO().post(): Argument 1 is not of type 'object'
"
,
"
Wrong parameter
"
"
Wrong parameter
"
);
);
});
test_name
=
'
should not throw error when giving no param to `allDocs`
'
;
test
(
test_name
,
1
,
function
()
{
var
result
,
jio
=
new
JIO
({
"
type
"
:
"
fake
"
,
"
id
"
:
"
Good para
"
},
{
"
workspace
"
:
{}
});
try
{
try
{
jio
.
allDocs
();
// allDocs([options], [callbacks]);
jio
.
allDocs
();
// allDocs([options], [callbacks]);
...
@@ -66,59 +69,16 @@
...
@@ -66,59 +69,16 @@
deepEqual
(
result
,
"
No error thrown
"
,
"
Good parameter
"
);
deepEqual
(
result
,
"
No error thrown
"
,
"
Good parameter
"
);
});
});
/**
test
(
'
should return an error when a storage type is given
'
,
1
,
function
()
{
* Tests asynchrony
var
jio
=
new
JIO
({
*/
test
(
"
Asynchrony
"
,
function
()
{
var
workspace
=
{},
clock
,
jio
,
count
=
0
;
expect
(
8
);
clock
=
this
.
sandbox
.
useFakeTimers
();
jio
=
new
JIO
({
"
type
"
:
"
fake
"
,
"
id
"
:
"
Asynchrony
"
},
{
"
workspace
"
:
workspace
});
jio
.
post
({}).
done
(
function
()
{
count
+=
1
;
deepEqual
(
count
,
6
,
"
Command done
"
);
}).
progress
(
function
()
{
count
+=
1
;
deepEqual
(
count
,
3
,
"
Command notifiy
"
);
});
count
+=
1
;
deepEqual
(
count
,
1
,
"
JIO post
"
);
ok
(
!
commands
[
'
Asynchrony/post
'
],
"
Command not called yet
"
);
clock
.
tick
(
1
);
count
+=
1
;
deepEqual
(
count
,
2
,
"
Next instructions
"
);
ok
(
commands
[
'
Asynchrony/post
'
],
"
Command called
"
);
commands
[
'
Asynchrony/post
'
].
notify
();
count
+=
1
;
deepEqual
(
count
,
4
,
"
Next timer
"
);
commands
[
'
Asynchrony/post
'
].
success
({
"
id
"
:
"
a
"
});
count
+=
1
;
deepEqual
(
count
,
5
,
"
Command success requested
"
);
clock
.
tick
(
1
);
});
/**
* Tests a storage initialization error
*/
test
(
'
Description Error
'
,
function
()
{
var
clock
,
jio
;
expect
(
2
);
clock
=
this
.
sandbox
.
useFakeTimers
();
jio
=
new
JIO
({
"
type
"
:
"
blue
"
"
type
"
:
"
blue
"
},
{
},
{
"
workspace
"
:
{}
"
workspace
"
:
{}
});
});
// Tests wrong storage type
stop
();
jio
.
post
({}).
always
(
function
(
answer
)
{
jio
.
post
({}).
always
(
function
(
answer
)
{
start
();
deepEqual
(
answer
,
{
deepEqual
(
answer
,
{
"
error
"
:
"
internal_storage_error
"
,
"
error
"
:
"
internal_storage_error
"
,
"
message
"
:
"
Check if the storage description respects the
"
+
"
message
"
:
"
Check if the storage description respects the
"
+
...
@@ -129,19 +89,21 @@
...
@@ -129,19 +89,21 @@
"
result
"
:
"
error
"
,
"
result
"
:
"
error
"
,
"
status
"
:
551
,
"
status
"
:
551
,
"
statusText
"
:
"
Internal Storage Error
"
"
statusText
"
:
"
Internal Storage Error
"
},
"
Unknown storage
"
);
},
"
Unknown storage error
"
);
});
});
});
clock
.
tick
(
1
);
// Tests wrong storage description
test
(
'
should return an error when a description is given
'
,
1
,
function
()
{
jio
=
new
JIO
({
var
jio
=
new
JIO
({
"
type
"
:
"
fake
"
,
"
type
"
:
"
fake
"
,
"
id
"
:
""
"
id
"
:
""
},
{
},
{
"
workspace
"
:
{}
"
workspace
"
:
{}
});
});
stop
();
jio
.
post
({}).
always
(
function
(
answer
)
{
jio
.
post
({}).
always
(
function
(
answer
)
{
start
();
deepEqual
(
answer
,
{
deepEqual
(
answer
,
{
"
error
"
:
"
internal_storage_error
"
,
"
error
"
:
"
internal_storage_error
"
,
"
message
"
:
"
Check if the storage description respects the
"
+
"
message
"
:
"
Check if the storage description respects the
"
+
...
@@ -154,126 +116,194 @@
...
@@ -154,126 +116,194 @@
"
statusText
"
:
"
Internal Storage Error
"
"
statusText
"
:
"
Internal Storage Error
"
},
"
Initialization error
"
);
},
"
Initialization error
"
);
});
});
clock
.
tick
(
1
);
});
});
/**
test
(
'
should fail after default command timeout
'
,
2
,
function
()
{
* Tests a command which does not respond
var
i
,
called
=
false
,
jio
=
new
JIO
({
*/
test
(
'
No Response or Response Timeout
'
,
function
()
{
var
clock
,
jio
,
state
;
expect
(
5
);
clock
=
this
.
sandbox
.
useFakeTimers
();
jio
=
new
JIO
({
"
type
"
:
"
fake
"
,
"
type
"
:
"
fake
"
,
"
id
"
:
"
1 No Respons
"
"
id
"
:
"
1 No Respons
"
},
{
},
{
"
workspace
"
:
{}
"
workspace
"
:
{}
});
});
// tests default timeout
stop
();
jio
.
post
({}).
always
(
function
(
answer
)
{
jio
.
post
({}).
always
(
function
(
answer
)
{
var
message
=
(
answer
&&
answer
.
message
)
||
"
Timeout
"
;
called
=
true
;
if
(
i
!==
undefined
)
{
start
();
clearTimeout
(
i
);
}
delete
answer
.
message
;
deepEqual
(
answer
,
{
deepEqual
(
answer
,
{
"
error
"
:
"
request_timeout
"
,
"
error
"
:
"
request_timeout
"
,
"
message
"
:
"
Operation canceled after around
"
+
"
10000 milliseconds of inactivity.
"
,
"
method
"
:
"
post
"
,
"
method
"
:
"
post
"
,
"
result
"
:
"
error
"
,
"
result
"
:
"
error
"
,
"
reason
"
:
"
timeout
"
,
"
reason
"
:
"
timeout
"
,
"
status
"
:
408
,
"
status
"
:
408
,
"
statusText
"
:
"
Request Timeout
"
"
statusText
"
:
"
Request Timeout
"
},
"
Timeout error (default timeout)
"
);
},
message
);
});
});
clock
.
tick
(
1
);
clock
.
tick
(
10000
);
// wait 10 seconds
setTimeout
(
function
()
{
ok
(
!
called
,
"
callback
"
+
(
called
?
""
:
"
not
"
)
+
"
called
"
);
},
9999
);
setTimeout
(
function
()
{
commands
[
'
1 No Respons/post
'
].
free
();
commands
[
'
1 No Respons/post
'
].
free
();
},
100
);
jio
=
new
JIO
({
i
=
setTimeout
(
function
()
{
i
=
undefined
;
start
();
ok
(
false
,
"
No response
"
);
},
11000
);
});
test
(
'
should fail after storage inactivity timeout
'
,
2
,
function
()
{
var
i
,
called
=
false
,
jio
=
new
JIO
({
"
type
"
:
"
fake
"
,
"
type
"
:
"
fake
"
,
"
id
"
:
"
2 No Respons
"
"
id
"
:
"
2 No Respons
"
},
{
},
{
"
workspace
"
:
{}
"
workspace
"
:
{}
});
});
// tests storage timeout
stop
();
state
=
"
Not called yet
"
;
jio
.
post
({}).
always
(
function
(
answer
)
{
jio
.
post
({}).
always
(
function
(
answer
)
{
state
=
"
Called
"
;
var
message
=
(
answer
&&
answer
.
message
)
||
"
Timeout
"
;
called
=
true
;
if
(
i
!==
undefined
)
{
start
();
clearTimeout
(
i
);
}
delete
answer
.
message
;
deepEqual
(
answer
,
{
deepEqual
(
answer
,
{
"
error
"
:
"
request_timeout
"
,
"
error
"
:
"
request_timeout
"
,
"
message
"
:
"
Operation canceled after around
"
+
"
10000 milliseconds of inactivity.
"
,
"
method
"
:
"
post
"
,
"
method
"
:
"
post
"
,
"
result
"
:
"
error
"
,
"
result
"
:
"
error
"
,
"
reason
"
:
"
timeout
"
,
"
reason
"
:
"
timeout
"
,
"
status
"
:
408
,
"
status
"
:
408
,
"
statusText
"
:
"
Request Timeout
"
"
statusText
"
:
"
Request Timeout
"
},
"
Timeout error (storage timeout reset)
"
);
},
message
);
});
});
clock
.
tick
(
1
);
setTimeout
(
function
()
{
clock
.
tick
(
4999
);
// wait 5 seconds
commands
[
'
2 No Respons/post
'
].
notify
();
commands
[
'
2 No Respons/post
'
].
notify
();
clock
.
tick
(
5000
);
// wait 5 seconds
},
5000
);
deepEqual
(
state
,
"
Not called yet
"
,
"
Check callback state.
"
);
clock
.
tick
(
5000
);
// wait 5 seconds
setTimeout
(
function
()
{
commands
[
'
2 No Respons/post
'
].
free
();
commands
[
'
2 No Respons/post
'
].
free
();
},
6000
);
jio
=
new
JIO
({
setTimeout
(
function
()
{
ok
(
!
called
,
"
callback
"
+
(
called
?
""
:
"
not
"
)
+
"
called
"
);
},
14999
);
i
=
setTimeout
(
function
()
{
i
=
undefined
;
start
();
ok
(
false
,
"
No response
"
);
},
16000
);
});
test
(
'
should fail after jio option default timeout
'
,
2
,
function
()
{
var
i
,
called
=
false
,
jio
=
new
JIO
({
"
type
"
:
"
fake
"
,
"
type
"
:
"
fake
"
,
"
id
"
:
"
3 No Respons
"
"
id
"
:
"
3 No Respons
"
},
{
},
{
"
workspace
"
:
{},
"
workspace
"
:
{},
"
default_timeout
"
:
2
"
default_timeout
"
:
2
000
});
});
// tests jio option timeout
stop
();
jio
.
post
({}).
always
(
function
(
answer
)
{
jio
.
post
({}).
always
(
function
(
answer
)
{
var
message
=
(
answer
&&
answer
.
message
)
||
"
Timeout
"
;
called
=
true
;
if
(
i
!==
undefined
)
{
start
();
clearTimeout
(
i
);
}
delete
answer
.
message
;
deepEqual
(
answer
,
{
deepEqual
(
answer
,
{
"
error
"
:
"
request_timeout
"
,
"
error
"
:
"
request_timeout
"
,
"
message
"
:
"
Operation canceled after around
"
+
"
2 milliseconds of inactivity.
"
,
"
method
"
:
"
post
"
,
"
method
"
:
"
post
"
,
"
result
"
:
"
error
"
,
"
result
"
:
"
error
"
,
"
reason
"
:
"
timeout
"
,
"
reason
"
:
"
timeout
"
,
"
status
"
:
408
,
"
status
"
:
408
,
"
statusText
"
:
"
Request Timeout
"
"
statusText
"
:
"
Request Timeout
"
},
"
Timeout error (specific default timeout)
"
);
},
message
);
});
setTimeout
(
function
()
{
commands
[
'
3 No Respons/post
'
].
free
();
},
100
);
setTimeout
(
function
()
{
ok
(
!
called
,
"
callback
"
+
(
called
?
""
:
"
not
"
)
+
"
called
"
);
},
1999
);
i
=
setTimeout
(
function
()
{
i
=
undefined
;
start
();
ok
(
false
,
"
No response
"
);
},
3000
);
});
test
(
'
should fail after command option timeout
'
,
2
,
function
()
{
var
i
,
called
=
false
,
jio
=
new
JIO
({
"
type
"
:
"
fake
"
,
"
id
"
:
"
4 No Respons
"
},
{
"
workspace
"
:
{},
"
default_timeout
"
:
2000
});
});
clock
.
tick
(
1
);
clock
.
tick
(
1
);
// tests command option timeout
stop
();
jio
.
post
({},
{
"
timeout
"
:
50
}).
always
(
function
(
answer
)
{
jio
.
post
({},
{
"
timeout
"
:
3000
}).
always
(
function
(
answer
)
{
var
message
=
(
answer
&&
answer
.
message
)
||
"
Timeout
"
;
called
=
true
;
if
(
i
!==
undefined
)
{
start
();
clearTimeout
(
i
);
}
delete
answer
.
message
;
deepEqual
(
answer
,
{
deepEqual
(
answer
,
{
"
error
"
:
"
request_timeout
"
,
"
error
"
:
"
request_timeout
"
,
"
message
"
:
"
Operation canceled after around
"
+
"
50 milliseconds of inactivity.
"
,
"
method
"
:
"
post
"
,
"
method
"
:
"
post
"
,
"
result
"
:
"
error
"
,
"
result
"
:
"
error
"
,
"
reason
"
:
"
timeout
"
,
"
reason
"
:
"
timeout
"
,
"
status
"
:
408
,
"
status
"
:
408
,
"
statusText
"
:
"
Request Timeout
"
"
statusText
"
:
"
Request Timeout
"
},
"
Timeout error (command timeout)
"
);
},
message
);
});
});
clock
.
tick
(
1
);
clock
.
tick
(
49
);
setTimeout
(
function
()
{
commands
[
'
4 No Respons/post
'
].
free
();
},
1000
);
setTimeout
(
function
()
{
ok
(
!
called
,
"
callback
"
+
(
called
?
""
:
"
not
"
)
+
"
called
"
);
},
2999
);
i
=
setTimeout
(
function
()
{
i
=
undefined
;
start
();
ok
(
false
,
"
No response
"
);
},
4000
);
});
});
/**
test
(
'
should fail when command succeed with a bad response
'
,
1
,
function
()
{
* Tests wrong responses
var
jio
=
new
JIO
({
*/
test
(
'
Invalid Response
'
,
function
()
{
var
clock
,
jio
;
expect
(
2
);
clock
=
this
.
sandbox
.
useFakeTimers
();
jio
=
new
JIO
({
"
type
"
:
"
fake
"
,
"
type
"
:
"
fake
"
,
"
id
"
:
"
1 Invalid Re
"
"
id
"
:
"
1 Invalid Re
"
},
{
},
{
"
workspace
"
:
{}
"
workspace
"
:
{}
});
});
stop
();
jio
.
post
({}).
always
(
function
(
answer
)
{
jio
.
post
({}).
always
(
function
(
answer
)
{
start
();
deepEqual
(
answer
,
{
deepEqual
(
answer
,
{
"
error
"
:
"
internal_storage_error
"
,
"
error
"
:
"
internal_storage_error
"
,
"
message
"
:
"
New document id have to be specified
"
,
"
message
"
:
"
New document id have to be specified
"
,
...
@@ -282,20 +312,24 @@
...
@@ -282,20 +312,24 @@
"
reason
"
:
"
invalid response
"
,
"
reason
"
:
"
invalid response
"
,
"
status
"
:
551
,
"
status
"
:
551
,
"
statusText
"
:
"
Internal Storage Error
"
"
statusText
"
:
"
Internal Storage Error
"
},
"
Invalid Post R
esponse
"
);
},
"
r
esponse
"
);
});
});
clock
.
tick
(
1
);
setTimeout
(
function
()
{
commands
[
'
1 Invalid Re/post
'
].
success
();
commands
[
'
1 Invalid Re/post
'
].
success
();
clock
.
tick
(
1
);
},
50
);
});
jio
=
new
JIO
({
test
(
'
should fail when command end with a bad error
'
,
1
,
function
()
{
var
jio
=
new
JIO
({
"
type
"
:
"
fake
"
,
"
type
"
:
"
fake
"
,
"
id
"
:
"
2 Invalid Re
"
"
id
"
:
"
2 Invalid Re
"
},
{
},
{
"
workspace
"
:
{}
"
workspace
"
:
{}
});
});
stop
();
jio
.
post
({}).
always
(
function
(
answer
)
{
jio
.
post
({}).
always
(
function
(
answer
)
{
start
();
deepEqual
(
answer
,
{
deepEqual
(
answer
,
{
"
error
"
:
"
internal_storage_error
"
,
"
error
"
:
"
internal_storage_error
"
,
"
message
"
:
"
Unknown status
\"
undefined
\"
"
,
"
message
"
:
"
Unknown status
\"
undefined
\"
"
,
...
@@ -304,109 +338,49 @@
...
@@ -304,109 +338,49 @@
"
result
"
:
"
error
"
,
"
result
"
:
"
error
"
,
"
status
"
:
551
,
"
status
"
:
551
,
"
statusText
"
:
"
Internal Storage Error
"
"
statusText
"
:
"
Internal Storage Error
"
},
"
Invalid Post Error R
esponse
"
);
},
"
r
esponse
"
);
});
});
clock
.
tick
(
1
);
setTimeout
(
function
()
{
commands
[
'
2 Invalid Re/post
'
].
error
();
commands
[
'
2 Invalid Re/post
'
].
error
();
clock
.
tick
(
1
);
},
50
);
});
});
/**
test
(
'
should succeed when giving a good `post` response
'
,
1
,
function
()
{
* Tests valid responses
var
jio
=
new
JIO
({
*/
test
(
'
Valid Responses & Callbacks
'
,
function
()
{
var
clock
,
jio
,
o
=
{};
expect
(
9
);
clock
=
this
.
sandbox
.
useFakeTimers
();
jio
=
new
JIO
({
"
type
"
:
"
fake
"
,
"
type
"
:
"
fake
"
,
"
id
"
:
"
Valid
Resp
"
"
id
"
:
"
Valid
post
"
},
{
},
{
"
workspace
"
:
{}
"
workspace
"
:
{}
});
});
// Tests post command callbacks post(metadata).always(onResponse) +
stop
();
// valid response.
jio
.
post
({}).
always
(
function
(
answer
)
{
o
.
message
=
"
Post Command: post(metadata).always(function (answer) {..})
"
+
start
();
"
+ valid response.
"
;
jio
.
post
({}).
done
(
function
()
{
o
.
called
=
'
done
'
;
}).
always
(
function
(
answer
)
{
ok
(
o
.
called
===
'
done
'
,
"
Done callback called first
"
);
deepEqual
(
answer
,
{
deepEqual
(
answer
,
{
"
id
"
:
"
document id a
"
,
"
id
"
:
"
document id a
"
,
"
method
"
:
"
post
"
,
"
method
"
:
"
post
"
,
"
result
"
:
"
success
"
,
"
result
"
:
"
success
"
,
"
status
"
:
201
,
"
status
"
:
201
,
"
statusText
"
:
"
Created
"
"
statusText
"
:
"
Created
"
},
o
.
message
);
},
"
response
"
);
});
setTimeout
(
function
()
{
commands
[
'
Valid post/post
'
].
success
({
"
id
"
:
"
document id a
"
});
},
50
);
});
});
clock
.
tick
(
1
);
commands
[
'
Valid Resp/post
'
].
success
({
"
id
"
:
"
document id a
"
});
clock
.
tick
(
1
);
// Tests post command callbacks post(metadata).done(onSuccess).fail(onError)
test
(
'
`getAttachment` should respond blob
'
,
2
,
function
()
{
o
.
message
=
"
Post Command: post(metadata).done(function (answer) {..}).
"
+
var
jio
=
new
JIO
({
"
fail(function (answer) {..})
"
;
"
type
"
:
"
fake
"
,
jio
.
post
({}).
done
(
function
(
answer
)
{
"
id
"
:
"
Valid getA
"
deepEqual
(
answer
,
{
},
{
"
id
"
:
"
document id a
"
,
"
workspace
"
:
{}
"
method
"
:
"
post
"
,
"
result
"
:
"
success
"
,
"
status
"
:
201
,
"
statusText
"
:
"
Created
"
},
o
.
message
);
}).
fail
(
function
(
answer
)
{
deepEqual
(
answer
,
"
Should not fail
"
,
o
.
message
);
});
clock
.
tick
(
1
);
commands
[
'
Valid Resp/post
'
].
success
({
"
id
"
:
"
document id a
"
});
clock
.
tick
(
1
);
// Tests post command callbacks post(metadata, onResponse)
o
.
message
=
"
Post Command: post(metadata, function (err, response) {..})
"
;
jio
.
post
({},
function
(
err
,
response
)
{
if
(
err
)
{
return
deepEqual
(
err
,
"
Should not fail
"
,
o
.
message
);
}
deepEqual
(
response
,
{
"
id
"
:
"
document id a
"
,
"
method
"
:
"
post
"
,
"
result
"
:
"
success
"
,
"
status
"
:
201
,
"
statusText
"
:
"
Created
"
},
o
.
message
);
});
clock
.
tick
(
1
);
commands
[
'
Valid Resp/post
'
].
success
({
"
id
"
:
"
document id a
"
});
clock
.
tick
(
1
);
// Tests post command callbacks post(metadata, onSuccess, onError) + error
// response.
o
.
message
=
"
Post Command: post(metadata, function (response) {..},
"
+
"
function (err) {..}) + valid error response.
"
;
jio
.
post
({},
function
(
response
)
{
deepEqual
(
response
,
"
Should fail
"
,
o
.
message
);
},
function
(
err
)
{
deepEqual
(
err
,
{
"
status
"
:
409
,
"
statusText
"
:
"
Conflict
"
,
"
method
"
:
"
post
"
,
"
error
"
:
"
conflict
"
,
"
reason
"
:
"
unknown
"
,
"
result
"
:
"
error
"
,
"
message
"
:
""
},
o
.
message
);
});
});
clock
.
tick
(
1
);
commands
[
'
Valid Resp/post
'
].
error
(
'
conflict
'
);
clock
.
tick
(
1
);
// Tests getAttachment command string response
stop
();
jio
.
getAttachment
({
"
_id
"
:
"
a
"
,
"
_attachment
"
:
"
b
"
}).
jio
.
getAttachment
({
"
_id
"
:
"
a
"
,
"
_attachment
"
:
"
b
"
}).
always
(
function
(
answer
)
{
always
(
function
(
answer
)
{
start
();
ok
(
answer
.
data
instanceof
Blob
,
ok
(
answer
.
data
instanceof
Blob
,
"
Get Attachment Command: Blob should be returned
"
);
"
Get Attachment Command: Blob should be returned
"
);
delete
answer
.
data
;
delete
answer
.
data
;
...
@@ -419,46 +393,50 @@
...
@@ -419,46 +393,50 @@
"
statusText
"
:
"
Ok
"
"
statusText
"
:
"
Ok
"
});
});
});
});
clock
.
tick
(
1
);
setTimeout
(
function
()
{
commands
[
'
Valid Resp
/getAttachment
'
].
success
(
"
ok
"
,
{
commands
[
'
Valid getA
/getAttachment
'
].
success
(
"
ok
"
,
{
"
data
"
:
"
document id a
"
"
data
"
:
"
document id a
"
});
});
clock
.
tick
(
1
);
},
50
);
});
// Tests notify responses
o
.
notified
=
true
;
test
(
'
should be notified by the command
'
,
4
,
function
()
{
o
.
message
=
"
Synchronous Notify
"
;
var
i
=
0
,
jio
=
new
JIO
({
jio
.
post
({}).
progress
(
function
(
answer
)
{
deepEqual
(
answer
,
o
.
answer
,
o
.
message
);
});
clock
.
tick
(
1
);
o
.
answer
=
undefined
;
commands
[
'
Valid Resp/post
'
].
notify
();
o
.
answer
=
'
hoo
'
;
commands
[
'
Valid Resp/post
'
].
notify
(
o
.
answer
);
o
.
answer
=
'
Forbidden!!!
'
;
o
.
message
=
'
Notification forbidden after success
'
;
setTimeout
(
commands
[
'
Valid Resp/post
'
].
notify
,
2
);
commands
[
'
Valid Resp/post
'
].
success
();
clock
.
tick
(
2
);
});
/**
* Tests metadata values
*/
test
(
'
Metadata values
'
,
function
()
{
expect
(
9
);
var
o
,
clock
=
this
.
sandbox
.
useFakeTimers
(),
jio
=
new
JIO
({
"
type
"
:
"
fake
"
,
"
type
"
:
"
fake
"
,
"
id
"
:
"
Metadata v
"
"
id
"
:
"
Valid noti
"
},
{
},
{
"
workspace
"
:
{}
"
workspace
"
:
{}
});
});
o
=
{};
stop
();
jio
.
put
({
"
_id
"
:
"
a
"
}).
then
(
function
()
{
start
();
},
function
(
answer
)
{
start
();
deepEqual
(
answer
,
"
Error
"
,
"
should not fail
"
);
},
function
(
answer
)
{
deepEqual
(
answer
,
i
,
"
notified
"
);
ok
(
i
<
3
,
(
i
<
3
?
""
:
"
not
"
)
+
"
called before success
"
);
i
+=
1
;
});
setTimeout
(
function
()
{
var
notify
=
commands
[
'
Valid noti/put
'
].
notify
;
notify
(
0
);
notify
(
1
);
commands
[
'
Valid noti/put
'
].
success
();
notify
(
2
);
},
50
);
});
test
(
'
metadata values should be formatted on `post`
'
,
1
,
function
()
{
var
request
,
response
,
jio
=
new
JIO
({
"
type
"
:
"
fake
"
,
"
id
"
:
"
Metadata v
"
},
{
"
workspace
"
:
{}
});
o
.
request
=
{
request
=
{
"
_id
"
:
undefined
,
"
_id
"
:
undefined
,
"
number
"
:
-
13
,
"
number
"
:
-
13
,
"
date
"
:
new
Date
(
0
),
"
date
"
:
new
Date
(
0
),
...
@@ -480,7 +458,7 @@
...
@@ -480,7 +458,7 @@
"
wrong_array
"
:
[{},
null
,
{
"
blue
"
:
"
green
"
}]
"
wrong_array
"
:
[{},
null
,
{
"
blue
"
:
"
green
"
}]
};
};
o
.
response
=
{
response
=
{
"
number
"
:
-
13
,
"
number
"
:
-
13
,
"
date
"
:
new
Date
(
0
).
toJSON
(),
"
date
"
:
new
Date
(
0
).
toJSON
(),
"
boolean
"
:
true
,
"
boolean
"
:
true
,
...
@@ -491,90 +469,134 @@
...
@@ -491,90 +469,134 @@
"
toJSON
"
:
"
hey!
"
"
toJSON
"
:
"
hey!
"
};
};
jio
.
post
(
o
.
request
);
stop
();
clock
.
tick
(
1
);
jio
.
post
(
request
);
setTimeout
(
function
()
{
start
();
deepEqual
(
deepEqual
(
commands
[
"
Metadata v/post
"
].
param
,
commands
[
"
Metadata v/post
"
].
param
,
o
.
response
,
response
,
"
Post
"
"
Post
"
);
);
commands
[
"
Metadata v/post
"
].
success
();
commands
[
"
Metadata v/post
"
].
success
();
clock
.
tick
(
1
);
},
50
);
o
.
request
.
_id
=
'
a
'
;
// o.request._id = 'a';
o
.
response
.
_id
=
'
a
'
;
// o.response._id = 'a';
jio
.
put
(
o
.
request
);
// jio.put(o.request);
clock
.
tick
(
1
);
// clock.tick(1);
deepEqual
(
commands
[
"
Metadata v/put
"
].
param
,
o
.
response
,
"
Put
"
);
// deepEqual(commands["Metadata v/put"].param, o.response, "Put");
commands
[
"
Metadata v/put
"
].
success
();
// commands["Metadata v/put"].success();
clock
.
tick
(
1
);
// clock.tick(1);
jio
.
get
({
// jio.get({
"
_id
"
:
"
a
"
// "_id": "a"
});
// });
clock
.
tick
(
1
);
// clock.tick(1);
deepEqual
(
commands
[
"
Metadata v/get
"
].
param
,
{
// deepEqual(commands["Metadata v/get"].param, {
"
_id
"
:
"
a
"
// "_id": "a"
},
"
Get
"
);
// }, "Get");
commands
[
"
Metadata v/get
"
].
success
();
// commands["Metadata v/get"].success();
clock
.
tick
(
1
);
// clock.tick(1);
jio
.
remove
({
// jio.remove({
"
_id
"
:
"
a
"
// "_id": "a"
});
// });
clock
.
tick
(
1
);
// clock.tick(1);
deepEqual
(
commands
[
"
Metadata v/remove
"
].
param
,
{
// deepEqual(commands["Metadata v/remove"].param, {
"
_id
"
:
"
a
"
// "_id": "a"
},
"
Remove
"
);
// }, "Remove");
commands
[
"
Metadata v/remove
"
].
success
();
// commands["Metadata v/remove"].success();
clock
.
tick
(
1
);
// clock.tick(1);
jio
.
allDocs
();
});
clock
.
tick
(
1
);
deepEqual
(
commands
[
"
Metadata v/allDocs
"
].
param
,
{},
"
AllDocs
"
);
test
(
'
data should be converted to blob on `putAttachment`
'
,
3
,
function
()
{
commands
[
"
Metadata v/allDocs
"
].
success
();
var
request
,
jio
=
new
JIO
({
clock
.
tick
(
1
);
"
type
"
:
"
fake
"
,
"
id
"
:
"
Metadata v
"
},
{
"
workspace
"
:
{}
});
o
.
request
=
{
request
=
{
"
_id
"
:
"
a
"
,
"
_id
"
:
"
a
"
,
"
_attachment
"
:
"
body
"
,
"
_attachment
"
:
"
body
"
,
"
_data
"
:
"
b
"
,
"
_data
"
:
"
b
"
,
"
_mimetype
"
:
"
c
"
"
_mimetype
"
:
"
c
"
};
};
jio
.
putAttachment
(
o
.
request
);
clock
.
tick
(
1
);
stop
();
jio
.
putAttachment
(
request
);
setTimeout
(
function
()
{
start
();
ok
(
commands
[
"
Metadata v/putAttachment
"
].
param
.
_blob
instanceof
Blob
,
ok
(
commands
[
"
Metadata v/putAttachment
"
].
param
.
_blob
instanceof
Blob
,
"
Put Attachment + check blob
"
);
"
param._blob should be a blob
"
);
deepEqual
(
commands
[
"
Metadata v/putAttachment
"
].
param
.
_blob
.
type
,
"
c
"
,
"
param._blob type should be equal to request._mimetype
"
);
deepEqual
([
deepEqual
([
commands
[
"
Metadata v/putAttachment
"
].
param
.
_id
,
commands
[
"
Metadata v/putAttachment
"
].
param
.
_id
,
commands
[
"
Metadata v/putAttachment
"
].
param
.
_attachment
commands
[
"
Metadata v/putAttachment
"
].
param
.
_attachment
],
[
"
a
"
,
"
body
"
],
"
Put Attachment + check ids
"
);
],
[
"
a
"
,
"
body
"
],
"
param._id and param._attachment exist
"
);
commands
[
"
Metadata v/putAttachment
"
].
success
();
commands
[
"
Metadata v/putAttachment
"
].
success
();
clock
.
tick
(
1
);
},
50
);
});
o
.
request
.
_blob
=
new
Blob
([
'
d
'
],
{
"
type
"
:
"
e
"
});
delete
o
.
request
.
_mimetype
;
test
(
'
blob should be given to param on `putAttachment`
'
,
3
,
function
()
{
delete
o
.
request
.
_data
;
var
request
=
{},
jio
=
new
JIO
({
jio
.
putAttachment
(
o
.
request
);
"
type
"
:
"
fake
"
,
clock
.
tick
(
1
);
"
id
"
:
"
Metadata 2
"
ok
(
commands
[
"
Metadata v/putAttachment
"
].
param
.
_blob
===
o
.
request
.
_blob
,
},
{
"
Put Attachment with blob + check blob
"
);
"
workspace
"
:
{}
});
request
.
_id
=
"
a
"
;
request
.
_attachment
=
"
body
"
;
request
.
_blob
=
new
Blob
([
'
d
'
],
{
"
type
"
:
"
e
"
});
stop
();
jio
.
putAttachment
(
request
);
setTimeout
(
function
()
{
start
();
ok
(
commands
[
"
Metadata 2/putAttachment
"
].
param
.
_blob
===
request
.
_blob
,
"
param._blob should be the given blob
"
);
deepEqual
(
commands
[
"
Metadata 2/putAttachment
"
].
param
.
_blob
.
type
,
"
e
"
,
"
param._blob type should be equal to request._mimetype
"
);
deepEqual
([
deepEqual
([
commands
[
"
Metadata v/putAttachment
"
].
param
.
_id
,
commands
[
"
Metadata 2/putAttachment
"
].
param
.
_id
,
commands
[
"
Metadata v/putAttachment
"
].
param
.
_attachment
commands
[
"
Metadata 2/putAttachment
"
].
param
.
_attachment
],
[
"
a
"
,
"
body
"
],
"
Put Attachment with blob + check ids
"
);
],
[
"
a
"
,
"
body
"
],
"
param._id and param._attachment exist
"
);
commands
[
"
Metadata v/putAttachment
"
].
success
();
commands
[
"
Metadata 2/putAttachment
"
].
success
();
clock
.
tick
(
1
);
},
50
);
});
test
(
'
no param should be given to `allDocs`
'
,
1
,
function
()
{
var
jio
=
new
JIO
({
"
type
"
:
"
fake
"
,
"
id
"
:
"
Metadata v
"
},
{
"
workspace
"
:
{}
});
});
/**
stop
();
* Tests job retry
jio
.
allDocs
();
*/
setTimeout
(
function
()
{
test
(
"
Job Retry
"
,
function
()
{
start
();
var
clock
,
jio
,
state
;
deepEqual
(
commands
[
"
Metadata v/allDocs
"
].
param
,
{},
"
No param given
"
);
expect
(
4
);
commands
[
"
Metadata v/allDocs
"
].
success
();
clock
=
this
.
sandbox
.
useFakeTimers
();
},
50
);
});
test
(
"
job should respond 3 retries to return an error
"
,
4
,
function
()
{
var
jio
,
state
;
jio
=
new
JIO
({
jio
=
new
JIO
({
"
type
"
:
"
fake
"
,
"
type
"
:
"
fake
"
,
"
id
"
:
"
1 Job Retry
"
"
id
"
:
"
1 Job Retry
"
...
@@ -582,6 +604,7 @@
...
@@ -582,6 +604,7 @@
"
workspace
"
:
{}
"
workspace
"
:
{}
});
});
stop
();
state
=
"
Not called yet
"
;
state
=
"
Not called yet
"
;
jio
.
get
({
"
_id
"
:
"
a
"
}).
always
(
function
(
answer
)
{
jio
.
get
({
"
_id
"
:
"
a
"
}).
always
(
function
(
answer
)
{
state
=
"
Called
"
;
state
=
"
Called
"
;
...
@@ -596,30 +619,29 @@
...
@@ -596,30 +619,29 @@
"
statusText
"
:
"
Internal Server Error
"
"
statusText
"
:
"
Internal Server Error
"
},
"
Error response
"
);
},
"
Error response
"
);
});
});
clock
.
tick
(
1
);
setTimeout
(
function
()
{
commands
[
'
1 Job Retry/get
'
].
retry
(
'
internal_server_error
'
);
commands
[
'
1 Job Retry/get
'
].
retry
(
'
internal_server_error
'
);
clock
.
tick
(
1
);
},
50
);
// wait 50 ms
setTimeout
(
function
()
{
deepEqual
(
state
,
"
Not called yet
"
,
"
Check callback state.
"
);
deepEqual
(
state
,
"
Not called yet
"
,
"
Check callback state.
"
);
},
100
);
// wait 50 ms
clock
.
tick
(
1999
);
setTimeout
(
function
()
{
commands
[
'
1 Job Retry/get
'
].
retry
(
'
internal_server_error
'
);
commands
[
'
1 Job Retry/get
'
].
retry
(
'
internal_server_error
'
);
clock
.
tick
(
1
);
},
2150
);
// wait 2050 ms
setTimeout
(
function
()
{
deepEqual
(
state
,
"
Not called yet
"
,
"
Check callback state.
"
);
deepEqual
(
state
,
"
Not called yet
"
,
"
Check callback state.
"
);
},
2200
);
// wait 50 ms
clock
.
tick
(
3999
);
setTimeout
(
function
()
{
commands
[
'
1 Job Retry/get
'
].
retry
(
'
internal_server_error
'
);
commands
[
'
1 Job Retry/get
'
].
retry
(
'
internal_server_error
'
);
clock
.
tick
(
1
);
},
6250
);
// wait 4050 ms
setTimeout
(
function
()
{
start
();
deepEqual
(
state
,
"
Called
"
,
"
Check callback state.
"
);
deepEqual
(
state
,
"
Called
"
,
"
Check callback state.
"
);
},
6300
);
// wait 50 ms
});
});
/**
test
(
"
Job Management
"
,
8
,
function
()
{
* Tests job management
var
tmp
,
workspace
=
{},
jio
,
o
=
{};
*/
test
(
"
Job Management
"
,
function
()
{
var
workspace
=
{},
clock
,
jio
,
o
=
{};
expect
(
8
);
clock
=
this
.
sandbox
.
useFakeTimers
();
jio
=
new
JIO
({
jio
=
new
JIO
({
"
type
"
:
"
fake
"
,
"
type
"
:
"
fake
"
,
"
id
"
:
"
1 Job Manage
"
"
id
"
:
"
1 Job Manage
"
...
@@ -627,8 +649,9 @@
...
@@ -627,8 +649,9 @@
"
workspace
"
:
workspace
"
workspace
"
:
workspace
});
});
stop
();
// Launch a get command, check the workspace and then respond
// Launch a get command, check the workspace and then respond
jio
.
get
({
"
_id
"
:
"
a
"
},
{
"
max_retry
"
:
2
,
"
timeout
"
:
12
}).
jio
.
get
({
"
_id
"
:
"
a
"
},
{
"
max_retry
"
:
2
,
"
timeout
"
:
12
00
}).
always
(
function
(
answer
)
{
always
(
function
(
answer
)
{
deepEqual
(
answer
,
{
deepEqual
(
answer
,
{
"
id
"
:
"
a
"
,
"
id
"
:
"
a
"
,
...
@@ -641,31 +664,32 @@
...
@@ -641,31 +664,32 @@
});
});
o
.
job1
=
{
o
.
job1
=
{
"
kwargs
"
:
{
"
_id
"
:
"
a
"
},
"
kwargs
"
:
{
"
_id
"
:
"
a
"
},
"
options
"
:
{
"
max_retry
"
:
2
,
"
timeout
"
:
12
},
"
options
"
:
{
"
max_retry
"
:
2
,
"
timeout
"
:
12
00
},
"
storage_spec
"
:
{
"
type
"
:
"
fake
"
,
"
id
"
:
"
1 Job Manage
"
},
"
storage_spec
"
:
{
"
type
"
:
"
fake
"
,
"
id
"
:
"
1 Job Manage
"
},
"
method
"
:
"
get
"
,
"
method
"
:
"
get
"
,
"
created
"
:
new
Date
(),
//
"created": new Date(),
"
tried
"
:
1
,
"
tried
"
:
1
,
"
state
"
:
"
running
"
,
"
state
"
:
"
running
"
,
"
modified
"
:
new
Date
(),
//
"modified": new Date(),
"
max_retry
"
:
2
,
"
max_retry
"
:
2
,
"
timeout
"
:
12
,
"
timeout
"
:
12
00
,
"
id
"
:
1
"
id
"
:
1
};
};
deepEqual
(
workspace
,
{
tmp
=
workspace
[
"
jio/jobs/{
\"
id
\"
:
\"
1 Job Manage
\"
,
\"
type
\"
:
\"
fake
\"
}
"
];
"
jio/jobs/{
\"
id
\"
:
\"
1 Job Manage
\"
,
\"
type
\"
:
\"
fake
\"
}
"
:
jIO
.
util
.
tmp
=
JSON
.
parse
(
tmp
);
uniqueJSONStringify
([
o
.
job1
])
delete
tmp
[
0
].
created
;
},
'
Job added, workspace have one job
'
);
delete
tmp
[
0
].
modified
;
deepEqual
(
tmp
,
[
o
.
job1
],
'
workspace have one job
'
);
clock
.
tick
(
1
);
// now: 1 ms
setTimeout
(
function
()
{
commands
[
"
1 Job Manage/get
"
].
success
({
"
data
"
:
{
"
b
"
:
"
c
"
}});
commands
[
"
1 Job Manage/get
"
].
success
({
"
data
"
:
{
"
b
"
:
"
c
"
}});
clock
.
tick
(
1
);
// now: 2
ms
},
50
);
// wait 50
ms
setTimeout
(
function
()
{
deepEqual
(
workspace
,
{},
'
Job ended, empty workspace
'
);
deepEqual
(
workspace
,
{},
'
Job ended, empty workspace
'
);
// Launch a get command which launches another get command
// Launch a get command which launches another get command
// check workspace after every command and respond
// check workspace after every command and respond
jio
.
get
({
"
_id
"
:
"
b
"
},
{
"
max_retry
"
:
2
,
"
timeout
"
:
12
}).
jio
.
get
({
"
_id
"
:
"
b
"
},
{
"
max_retry
"
:
2
,
"
timeout
"
:
1200
}).
always
(
function
(
answer
)
{
always
(
function
(
answer
)
{
deepEqual
(
answer
,
{
deepEqual
(
answer
,
{
"
id
"
:
"
b
"
,
"
id
"
:
"
b
"
,
...
@@ -677,13 +701,15 @@
...
@@ -677,13 +701,15 @@
},
"
First job respond
"
);
},
"
First job respond
"
);
});
});
o
.
job1
.
kwargs
.
_id
=
'
b
'
;
o
.
job1
.
kwargs
.
_id
=
'
b
'
;
o
.
job1
.
created
=
new
Date
();
// o.job1.created = new Date();
o
.
job1
.
modified
=
new
Date
();
// o.job1.modified = new Date();
clock
.
tick
(
1
);
// now: 3 ms
},
100
);
// wait 50 ms
setTimeout
(
function
()
{
commands
[
"
1 Job Manage/get
"
].
storage
({
commands
[
"
1 Job Manage/get
"
].
storage
({
"
type
"
:
"
fake
"
,
"
type
"
:
"
fake
"
,
"
id
"
:
"
2 Job Manage
"
"
id
"
:
"
2 Job Manage
"
}).
get
({
"
_id
"
:
"
c
"
}).
always
(
function
(
answer
)
{
}).
get
({
"
_id
"
:
"
c
"
}).
always
(
function
(
answer
)
{
start
();
deepEqual
(
answer
,
{
deepEqual
(
answer
,
{
"
id
"
:
"
c
"
,
"
id
"
:
"
c
"
,
"
method
"
:
"
get
"
,
"
method
"
:
"
get
"
,
...
@@ -699,42 +725,42 @@
...
@@ -699,42 +725,42 @@
"
options
"
:
{},
"
options
"
:
{},
"
storage_spec
"
:
{
"
type
"
:
"
fake
"
,
"
id
"
:
"
2 Job Manage
"
},
"
storage_spec
"
:
{
"
type
"
:
"
fake
"
,
"
id
"
:
"
2 Job Manage
"
},
"
method
"
:
"
get
"
,
"
method
"
:
"
get
"
,
"
created
"
:
new
Date
(),
//
"created": new Date(),
"
tried
"
:
1
,
"
tried
"
:
1
,
"
state
"
:
"
running
"
,
"
state
"
:
"
running
"
,
"
modified
"
:
new
Date
(),
//
"modified": new Date(),
"
max_retry
"
:
2
,
"
max_retry
"
:
2
,
"
timeout
"
:
10000
,
"
timeout
"
:
10000
,
"
id
"
:
2
"
id
"
:
2
};
};
deepEqual
(
workspace
,
{
tmp
=
workspace
[
"
jio/jobs/{
\"
id
\"
:
\"
1 Job Manage
\"
,
\"
type
\"
:
\"
fake
\"
}
"
];
"
jio/jobs/{
\"
id
\"
:
\"
1 Job Manage
\"
,
\"
type
\"
:
\"
fake
\"
}
"
:
jIO
.
util
.
tmp
=
JSON
.
parse
(
tmp
);
uniqueJSONStringify
([
o
.
job1
,
o
.
job2
])
delete
tmp
[
0
].
created
;
},
'
Job calls another job, workspace have two jobs
'
);
delete
tmp
[
0
].
modified
;
delete
tmp
[
1
].
created
;
clock
.
tick
(
1
);
delete
tmp
[
1
].
modified
;
deepEqual
(
tmp
,
[
o
.
job1
,
o
.
job2
],
'
Job calls another job, workspace have two jobs
'
);
},
150
);
// wait 50 ms
setTimeout
(
function
()
{
commands
[
'
1 Job Manage/get
'
].
end
();
commands
[
'
1 Job Manage/get
'
].
end
();
deepEqual
(
workspace
,
{
tmp
=
workspace
[
"
jio/jobs/{
\"
id
\"
:
\"
1 Job Manage
\"
,
\"
type
\"
:
\"
fake
\"
}
"
];
"
jio/jobs/{
\"
id
\"
:
\"
1 Job Manage
\"
,
\"
type
\"
:
\"
fake
\"
}
"
:
jIO
.
util
.
tmp
=
JSON
.
parse
(
tmp
);
uniqueJSONStringify
([
o
.
job2
])
delete
tmp
[
0
].
created
;
},
'
First Job ended, second still there
'
);
delete
tmp
[
0
].
modified
;
deepEqual
(
tmp
,
[
o
.
job2
],
'
First Job ended, second still there
'
);
commands
[
'
1 Job Manage/get
'
].
success
({
"
data
"
:
{
"
c
"
:
"
d
"
}});
commands
[
'
1 Job Manage/get
'
].
success
({
"
data
"
:
{
"
c
"
:
"
d
"
}});
commands
[
'
2 Job Manage/get
'
].
success
({
"
data
"
:
{
"
d
"
:
"
e
"
}});
commands
[
'
2 Job Manage/get
'
].
success
({
"
data
"
:
{
"
d
"
:
"
e
"
}});
deepEqual
(
workspace
,
{},
'
No more job in the queue
'
);
deepEqual
(
workspace
,
{},
'
No more job in the queue
'
);
},
200
);
// wait 50 ms
clock
.
tick
(
1
);
// success 1 and 2
});
});
/**
test
(
'
job state running, job recovery
'
,
2
,
function
()
{
* Test job recovery
var
workspace
,
jio
;
*/
test
(
'
Job Recovery
'
,
function
()
{
expect
(
4
);
var
workspace
,
clock
,
jio
;
clock
=
this
.
sandbox
.
useFakeTimers
();
//////////////////////////////
//////////////////////////////
// Running job recovery
// Running job recovery
...
@@ -748,13 +774,14 @@
...
@@ -748,13 +774,14 @@
"
workspace
"
:
workspace
"
workspace
"
:
workspace
});
});
stop
();
// create a job
// create a job
jio
.
post
({});
jio
.
post
({});
// copy workspace when job is running
// copy workspace when job is running
workspace
=
jIO
.
util
.
deepClone
(
workspace
);
workspace
=
jIO
.
util
.
deepClone
(
workspace
);
clock
.
tick
(
1
);
// now: 1 ms
setTimeout
(
function
()
{
commands
[
'
Job Recove/post
'
].
success
({
"
id
"
:
"
a
"
});
commands
[
'
Job Recove/post
'
].
success
({
"
id
"
:
"
a
"
});
},
50
);
// create instance with copied workspace
// create instance with copied workspace
jio
=
new
JIO
({
jio
=
new
JIO
({
"
type
"
:
"
fake
"
,
"
type
"
:
"
fake
"
,
...
@@ -763,22 +790,29 @@
...
@@ -763,22 +790,29 @@
"
workspace
"
:
workspace
"
workspace
"
:
workspace
});
});
clock
.
tick
(
19998
);
// now: 19999 ms
setTimeout
(
function
()
{
if
(
commands
[
'
Job Recove/post
'
])
{
if
(
commands
[
'
Job Recove/post
'
])
{
ok
(
false
,
"
Command called, job recovered to earlier
"
);
ok
(
false
,
"
Command called, job recovered to earlier
"
);
}
}
clock
.
tick
(
1
);
// now: 20000 ms
},
19999
);
setTimeout
(
function
()
{
if
(
!
commands
[
'
Job Recove/post
'
])
{
if
(
!
commands
[
'
Job Recove/post
'
])
{
ok
(
false
,
"
Command not called, job recovery failed
"
);
ok
(
false
,
"
Command not called, job recovery failed
"
);
}
else
{
}
else
{
ok
(
true
,
"
Command called, job recovery ok
"
);
ok
(
true
,
"
Command called, job recovery ok
"
);
}
}
commands
[
'
Job Recove/post
'
].
success
({
"
id
"
:
"
a
"
});
commands
[
'
Job Recove/post
'
].
success
({
"
id
"
:
"
a
"
});
clock
.
tick
(
1
);
// now: 20001 ms
},
20050
);
setTimeout
(
function
()
{
start
();
deepEqual
(
workspace
,
{},
'
No more job in the queue
'
);
deepEqual
(
workspace
,
{},
'
No more job in the queue
'
);
clock
.
tick
(
79999
);
// now: 100000 ms
},
20100
);
});
test
(
'
job state waiting for time, job recovery
'
,
2
,
function
()
{
var
workspace
,
jio
;
//////////////////////////////
//////////////////////////////
// Waiting for time job recovery
// Waiting for time job recovery
...
@@ -786,53 +820,60 @@
...
@@ -786,53 +820,60 @@
// create instance
// create instance
jio
=
new
JIO
({
jio
=
new
JIO
({
"
type
"
:
"
fake
"
,
"
type
"
:
"
fake
"
,
"
id
"
:
"
Job Recov
e
"
"
id
"
:
"
Job Recov
w
"
},
{
},
{
"
workspace
"
:
workspace
"
workspace
"
:
workspace
});
});
stop
();
// create a job
// create a job
jio
.
post
({});
jio
.
post
({});
clock
.
tick
(
1
);
// now: 1 ms
setTimeout
(
function
()
{
// copy workspace when job is waiting
// copy workspace when job is waiting
commands
[
'
Job Recove
/post
'
].
retry
();
commands
[
'
Job Recovw
/post
'
].
retry
();
workspace
=
jIO
.
util
.
deepClone
(
workspace
);
workspace
=
jIO
.
util
.
deepClone
(
workspace
);
clock
.
tick
(
2000
);
// now: 2001 ms
},
50
);
commands
[
'
Job Recove/post
'
].
success
({
"
id
"
:
"
a
"
});
setTimeout
(
function
()
{
commands
[
'
Job Recovw/post
'
].
success
({
"
id
"
:
"
a
"
});
},
2100
);
// create instance with copied workspace
// create instance with copied workspace
setTimeout
(
function
()
{
jio
=
new
JIO
({
jio
=
new
JIO
({
"
type
"
:
"
fake
"
,
"
type
"
:
"
fake
"
,
"
id
"
:
"
Job Recove
"
"
id
"
:
"
Job Recovw
"
},
{
},
{
"
workspace
"
:
workspace
"
workspace
"
:
workspace
});
});
clock
.
tick
(
17999
);
// now: 20000 ms
setTimeout
(
function
()
{
if
(
commands
[
'
Job Recove
/post
'
])
{
if
(
commands
[
'
Job Recovw
/post
'
])
{
ok
(
false
,
"
Command called, job recovered to earlier
"
);
ok
(
false
,
"
Command called, job recovered to earlier
"
);
}
}
clock
.
tick
(
1
);
// now: 20001 ms
},
19999
);
if
(
!
commands
[
'
Job Recove/post
'
])
{
setTimeout
(
function
()
{
if
(
!
commands
[
'
Job Recovw/post
'
])
{
ok
(
false
,
"
Command not called, job recovery failed
"
);
ok
(
false
,
"
Command not called, job recovery failed
"
);
}
else
{
}
else
{
ok
(
true
,
"
Command called, job recovery ok
"
);
ok
(
true
,
"
Command called, job recovery ok
"
);
}
}
commands
[
'
Job Recove
/post
'
].
success
({
"
id
"
:
"
a
"
});
commands
[
'
Job Recovw
/post
'
].
success
({
"
id
"
:
"
a
"
});
clock
.
tick
(
1
);
// now: 20002 ms
},
20050
);
setTimeout
(
function
()
{
start
();
deepEqual
(
workspace
,
{},
'
No more job in the queue
'
);
deepEqual
(
workspace
,
{},
'
No more job in the queue
'
);
clock
.
tick
(
79998
);
// now: 100000 ms
},
20100
);
},
51
);
//////////////////////////////
//////////////////////////////
// XXX Waiting for jobs job recovery
// XXX Waiting for jobs job recovery
});
});
test
(
'
Job Update
'
,
function
()
{
test
(
'
Job Update
'
,
5
,
function
()
{
expect
(
5
);
var
jio
,
o
=
{};
var
clock
,
jio
,
o
=
{};
clock
=
this
.
sandbox
.
useFakeTimers
();
o
.
workspace
=
{};
o
.
workspace
=
{};
jio
=
new
JIO
({
jio
=
new
JIO
({
...
@@ -842,6 +883,7 @@
...
@@ -842,6 +883,7 @@
"
workspace
"
:
o
.
workspace
"
workspace
"
:
o
.
workspace
});
});
stop
();
jio
.
put
({
"
_id
"
:
"
a
"
}).
always
(
function
(
answer
)
{
jio
.
put
({
"
_id
"
:
"
a
"
}).
always
(
function
(
answer
)
{
deepEqual
(
answer
,
{
deepEqual
(
answer
,
{
"
id
"
:
"
a
"
,
"
id
"
:
"
a
"
,
...
@@ -852,11 +894,13 @@
...
@@ -852,11 +894,13 @@
},
"
First put respond
"
);
},
"
First put respond
"
);
});
});
clock
.
tick
(
1
);
setTimeout
(
function
()
{
o
.
first_put_command
=
commands
[
"
Job Update/put
"
];
o
.
first_put_command
=
commands
[
"
Job Update/put
"
];
ok
(
o
.
first_put_command
,
"
First command called
"
);
ok
(
o
.
first_put_command
,
"
First command called
"
);
o
.
first_put_command
.
free
();
o
.
first_put_command
.
free
();
},
50
);
setTimeout
(
function
()
{
jio
.
put
({
"
_id
"
:
"
a
"
}).
always
(
function
(
answer
)
{
jio
.
put
({
"
_id
"
:
"
a
"
}).
always
(
function
(
answer
)
{
deepEqual
(
answer
,
{
deepEqual
(
answer
,
{
"
id
"
:
"
a
"
,
"
id
"
:
"
a
"
,
...
@@ -866,21 +910,23 @@
...
@@ -866,21 +910,23 @@
"
statusText
"
:
"
No Content
"
"
statusText
"
:
"
No Content
"
},
"
Second put respond
"
);
},
"
Second put respond
"
);
});
});
},
51
);
clock
.
tick
(
1
);
setTimeout
(
function
()
{
ok
(
commands
[
'
Job Update/put
'
]
===
undefined
,
ok
(
commands
[
'
Job Update/put
'
]
===
undefined
,
'
Second command not called
'
);
'
Second command not called
'
);
o
.
first_put_command
.
success
();
o
.
first_put_command
.
success
();
clock
.
tick
(
1
);
},
100
);
setTimeout
(
function
()
{
start
();
deepEqual
(
o
.
workspace
,
{},
'
No job in the queue
'
);
deepEqual
(
o
.
workspace
,
{},
'
No job in the queue
'
);
},
150
);
});
});
test
(
'
Job Wait
'
,
function
()
{
test
(
'
Job Wait
'
,
6
,
function
()
{
expect
(
6
);
var
jio
,
o
=
{};
var
clock
,
jio
,
o
=
{};
clock
=
this
.
sandbox
.
useFakeTimers
();
o
.
workspace
=
{};
o
.
workspace
=
{};
jio
=
new
JIO
({
jio
=
new
JIO
({
...
@@ -890,6 +936,7 @@
...
@@ -890,6 +936,7 @@
"
workspace
"
:
o
.
workspace
"
workspace
"
:
o
.
workspace
});
});
stop
();
jio
.
put
({
"
_id
"
:
"
a
"
}).
always
(
function
(
answer
)
{
jio
.
put
({
"
_id
"
:
"
a
"
}).
always
(
function
(
answer
)
{
deepEqual
(
answer
,
{
deepEqual
(
answer
,
{
"
id
"
:
"
a
"
,
"
id
"
:
"
a
"
,
...
@@ -900,11 +947,13 @@
...
@@ -900,11 +947,13 @@
},
"
First put respond
"
);
},
"
First put respond
"
);
});
});
clock
.
tick
(
1
);
setTimeout
(
function
()
{
o
.
first_put_command
=
commands
[
"
Job Wait/put
"
];
o
.
first_put_command
=
commands
[
"
Job Wait/put
"
];
ok
(
o
.
first_put_command
,
"
First command called
"
);
ok
(
o
.
first_put_command
,
"
First command called
"
);
o
.
first_put_command
.
free
();
o
.
first_put_command
.
free
();
},
50
);
setTimeout
(
function
()
{
jio
.
put
({
"
_id
"
:
"
a
"
,
"
a
"
:
"
b
"
}).
always
(
function
(
answer
)
{
jio
.
put
({
"
_id
"
:
"
a
"
,
"
a
"
:
"
b
"
}).
always
(
function
(
answer
)
{
deepEqual
(
answer
,
{
deepEqual
(
answer
,
{
"
id
"
:
"
a
"
,
"
id
"
:
"
a
"
,
...
@@ -914,24 +963,27 @@
...
@@ -914,24 +963,27 @@
"
statusText
"
:
"
No Content
"
"
statusText
"
:
"
No Content
"
},
"
Second put respond
"
);
},
"
Second put respond
"
);
});
});
},
51
);
clock
.
tick
(
1
);
setTimeout
(
function
()
{
ok
(
commands
[
'
Job Wait/put
'
]
===
undefined
,
ok
(
commands
[
'
Job Wait/put
'
]
===
undefined
,
'
Second command not called yet
'
);
'
Second command not called yet
'
);
o
.
first_put_command
.
success
();
o
.
first_put_command
.
success
();
clock
.
tick
(
1
);
},
100
);
setTimeout
(
function
()
{
ok
(
commands
[
'
Job Wait/put
'
],
'
Second command called
'
);
ok
(
commands
[
'
Job Wait/put
'
],
'
Second command called
'
);
commands
[
'
Job Wait/put
'
].
success
();
commands
[
'
Job Wait/put
'
].
success
();
clock
.
tick
(
1
);
},
150
);
setTimeout
(
function
()
{
start
();
deepEqual
(
o
.
workspace
,
{},
'
No job in the queue
'
);
deepEqual
(
o
.
workspace
,
{},
'
No job in the queue
'
);
},
200
);
});
});
test
(
'
Job Deny + Job condition addition
'
,
function
()
{
test
(
'
Job Deny + Job condition addition
'
,
2
,
function
()
{
expect
(
2
);
var
jio
,
workspace
=
{};
var
clock
,
jio
,
workspace
=
{};
clock
=
this
.
sandbox
.
useFakeTimers
();
jIO
.
addJobRuleCondition
(
'
isGetMethod
'
,
function
(
job
)
{
jIO
.
addJobRuleCondition
(
'
isGetMethod
'
,
function
(
job
)
{
return
job
.
method
===
'
get
'
;
return
job
.
method
===
'
get
'
;
...
@@ -950,6 +1002,7 @@
...
@@ -950,6 +1002,7 @@
}]
}]
});
});
stop
();
jio
.
get
({
"
_id
"
:
"
a
"
}).
always
(
function
(
answer
)
{
jio
.
get
({
"
_id
"
:
"
a
"
}).
always
(
function
(
answer
)
{
deepEqual
(
answer
,
{
deepEqual
(
answer
,
{
"
error
"
:
"
precondition_failed
"
,
"
error
"
:
"
precondition_failed
"
,
...
@@ -963,10 +1016,10 @@
...
@@ -963,10 +1016,10 @@
},
"
Get respond
"
);
},
"
Get respond
"
);
});
});
clock
.
tick
(
1
);
setTimeout
(
function
()
{
start
();
deepEqual
(
workspace
,
{},
'
No job in the queue
'
);
deepEqual
(
workspace
,
{},
'
No job in the queue
'
);
},
50
);
});
});
}));
}));
test/jio/util.js
View file @
cb071f1a
/*jslint indent: 2, maxlen: 80 */
/*jslint indent: 2, maxlen: 80 */
/*global define, exports, window, localStorage, ok, deepEqual, sinon */
/*global define, exports, window, require, localStorage, start, ok, deepEqual,
sinon */
(
function
(
dependencies
,
module
)
{
(
function
(
dependencies
,
module
)
{
"
use strict
"
;
"
use strict
"
;
...
@@ -7,13 +8,13 @@
...
@@ -7,13 +8,13 @@
return
define
(
dependencies
,
module
);
return
define
(
dependencies
,
module
);
}
}
if
(
typeof
exports
===
'
object
'
)
{
if
(
typeof
exports
===
'
object
'
)
{
module
(
exports
);
module
(
exports
,
require
(
'
sinon_qunit
'
)
);
}
}
if
(
typeof
window
===
'
object
'
)
{
if
(
typeof
window
===
'
object
'
)
{
window
.
test_util
=
{};
window
.
test_util
=
{};
module
(
window
.
test_util
);
module
(
window
.
test_util
);
}
}
}([
'
exports
'
],
function
(
exports
)
{
}([
'
exports
'
,
'
sinon_qunit
'
],
function
(
exports
)
{
"
use strict
"
;
"
use strict
"
;
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
...
...
test/tests.html
View file @
cb071f1a
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
<script
src=
"../lib/qunit/qunit.js"
></script>
<script
src=
"../lib/qunit/qunit.js"
></script>
<script
src=
"../lib/sinon/sinon.js"
></script>
<script
src=
"../lib/sinon/sinon.js"
></script>
<script
src=
"../lib/sinon/sinon-qunit.js"
></script>
<script
src=
"../lib/sinon/sinon-qunit.js"
></script>
<script
src=
"../
src/promy/promy
.js"
></script>
<script
src=
"../
lib/rsvp/rsvp-custom
.js"
></script>
<script
src=
"../src/sha256.amd.js"
></script>
<script
src=
"../src/sha256.amd.js"
></script>
<script
src=
"../jio.js"
></script>
<script
src=
"../jio.js"
></script>
<script
src=
"jio/util.js"
></script>
<script
src=
"jio/util.js"
></script>
...
...
test/tests.require.js
View file @
cb071f1a
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
require
.
config
({
require
.
config
({
"
paths
"
:
{
"
paths
"
:
{
"
promy
"
:
"
../src/promy/promy
"
,
"
rsvp
"
:
"
../lib/rsvp/rsvp-custom.amd
"
,
"
sha256
"
:
"
../src/sha256.amd
"
,
"
sha256
"
:
"
../src/sha256.amd
"
,
"
jio
"
:
"
../jio
"
,
"
jio
"
:
"
../jio
"
,
"
jio_tests
"
:
"
jio/tests
"
,
"
jio_tests
"
:
"
jio/tests
"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment