Skip to content

Commit

Permalink
add unit test for issue #98 with clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
yathit committed Oct 27, 2016
1 parent 0bd007d commit f7a353c
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 40 deletions.
24 changes: 24 additions & 0 deletions test/crud/issue_98_test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>Test for Race condition</title>
</head>
<body>

<script src="../../../closure-library/closure/goog/base.js"></script>
<script src="../../../closure-library/closure/goog/deps.js"></script>
<script type="text/javascript" src="../../../ydn-base/src/deps.js"></script>
<script type="text/javascript" src="../../src/deps.js"></script>
<script type="text/javascript" >
goog.require('ydn.debug');
goog.require('goog.userAgent');
goog.require('goog.testing.AsyncTestCase');
goog.require('goog.testing.jsunit');
goog.require('ydn.db.crud.Storage');
</script>
<script type="text/javascript" src="../../src/ydn/db/tr/inject.js"></script>
<script type="text/javascript" src="../../src/ydn/db/crud/inject.js"></script>
<script type="text/javascript" src="issue_98_test.js"></script>

</body>
</html>
66 changes: 66 additions & 0 deletions test/crud/issue_98_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

goog.require('goog.debug.Console');
goog.require('goog.testing.AsyncTestCase');
goog.require('goog.testing.jsunit');
goog.require('ydn.async');
goog.require('ydn.db.crud.Storage');
goog.require('ydn.debug');

var asyncTestCase = goog.testing.AsyncTestCase.createAndInstall();
var to_del = [];


var setUp = function() {
ydn.json.POLY_FILL = true;
};

var tearDown = function() {

};

function composite_index_test(type) {
var db_name = 'issue98';
var schema = {
stores: [
{
name: 'test',
keyPath: 'id',
indexes: [
{
keyPath: ['first', 'last']
},
{
keyPath: 'first'
},
{
keyPath: 'last'
}
]
}]};
var option = {mechanisms: [type]};
var db1 = new ydn.db.crud.Storage(db_name, schema, option);
asyncTestCase.waitForAsync('put in db1');
var data = {id: 1, first: 'First', last: 'Last'};
db1.put('test', data).addCallback(function() {
var db2 = new ydn.db.crud.Storage(db_name, schema, option);
asyncTestCase.continueTesting();
asyncTestCase.waitForAsync('values');
db1.close();
db2.values('test').addCallback(function(arr) {
assertObjectEquals(data, arr[0]);
asyncTestCase.continueTesting();
ydn.db.deleteDatabase(db_name, db2.getType());
db2.close();
});
});
to_del.push(db_name);
}

function test_composite_index_idb() {
composite_index_test('indexeddb');
}

function test_composite_index_websql() {
composite_index_test('websql');
}

41 changes: 1 addition & 40 deletions test/crud/race_2_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ var tearDown = function() {
}
};


function test_racy() {
var db_name = 'test_racy_1';
var schema = {
Expand All @@ -53,43 +52,5 @@ function test_racy() {
db2.close();
});
});
to_del.push(to_del);
to_del.push(db_name);
}

function test_issu98() {
var schema = {
stores: [
{
name: 'test',
keyPath: 'id',
indexes: [
{
keyPath: ['first', 'last']
},
{
keyPath: 'first'
},
{
keyPath: 'last'
}
]
}]};
var option = {mechanisms: ['websql']};
var db1 = new ydn.db.crud.Storage('issue98', schema, option);
asyncTestCase.waitForAsync('put in db1');
var data = {id: 1, first: 'First', last: 'Last'};
db1.put('test', data).addCallback(function() {
var db2 = new ydn.db.crud.Storage('issue98', schema, option);
asyncTestCase.continueTesting();
asyncTestCase.waitForAsync('values');
db1.close();
db2.values('test').addCallback(function(arr) {
assertArrayEquals(data, arr);
asyncTestCase.continueTesting();
ydn.db.deleteDatabase(db_name, db2.getType());
db2.close();
});
});
to_del.push(to_del);
}

0 comments on commit f7a353c

Please sign in to comment.