18 - Changing all hostname to host, fixing some async issues in tests

This commit is contained in:
Nicolas Dextraze
2017-01-28 18:04:58 -08:00
parent f97b7fff8e
commit 006b5b4791
29 changed files with 246 additions and 90 deletions

View File

@ -3,6 +3,7 @@ var client = require('../src/client');
module.exports = {
'Append One Event To Stream Happy Path': function(test) {
test.expect(2);
var event = client.createJsonEventData(uuid.v4(), {a: Math.random(), b: uuid.v4()}, null, 'testEvent');
this.conn.appendToStream(this.testStreamName, client.expectedVersion.any, event)
.then(function(result) {
@ -15,6 +16,7 @@ module.exports = {
});
},
'Append Multiple Events To Stream Happy Path': function(test) {
test.expect(2);
const expectedVersion = 25;
var events = [];
for(var i = 0; i <= expectedVersion; i++) {
@ -34,6 +36,7 @@ module.exports = {
});
},
'Append To Stream Wrong Expected Version': function(test) {
test.expect(1);
var event = client.createJsonEventData(uuid.v4(), {a: Math.random(), b: uuid.v4()}, null, 'testEvent');
this.conn.appendToStream(this.testStreamName, 10, event)
.then(function(result) {
@ -48,6 +51,7 @@ module.exports = {
});
},
'Append To Stream Deleted': function(test) {
test.expect(1);
var self = this;
this.conn.deleteStream(this.testStreamName, client.expectedVersion.noStream, true)
.then(function() {
@ -66,6 +70,7 @@ module.exports = {
});
},
'Append To Stream Access Denied': function(test) {
test.expect(1);
var self = this;
var metadata = {$acl: {$w: "$admins"}};
this.conn.setStreamMetadataRaw(this.testStreamName, client.expectedVersion.noStream, metadata)

View File

@ -0,0 +1,38 @@
var client = require('../../src/client');
var uuid = require('uuid');
var settings = {
log: {
info: console.log,
error: console.log,
debug: console.log
}
};
var gossipSeeds = [
new client.GossipSeed({host: 'localhost', port: 1113}),
new client.GossipSeed({host: 'localhost', port: 2113}),
new client.GossipSeed({host: 'localhost', port: 3113})
];
var conn = client.createConnection(settings, gossipSeeds);
console.log('Connecting...');
conn.on('connected', function (tcpEndPoint) {
console.log('Connect to', tcpEndPoint);
setTimeout(function () {
conn.appendToStream('test-' + uuid.v4(), client.expectedVersion.noStream, [
client.createJsonEventData(uuid.v4(), {abc: 123}, {}, 'myEvent')
]);
}, 5000);
});
conn.on('error', function (err) {
console.log(err.stack);
});
conn.on('closed', function (reason) {
console.log('Connection closed:', reason);
process.exit(-1);
});
conn.connect()
.catch(function (err) {
console.log(err.stack);
process.exit(-1);
});

View File

@ -12,7 +12,7 @@ if (process.env.TESTS_VERBOSE_LOGGING === '1') {
settings.log = new FileLogger('test-verbose.log');
}
var tcpEndPoint = {hostname: 'localhost', port: 1113};
var tcpEndPoint = {host: '192.168.33.10', port: 1113};
function setUp(cb) {
this.log = settings.log;

View File

@ -5,7 +5,8 @@ var testBase = require('./common/base_test');
module.exports = {
'Connect To Endpoint Happy Path': function(test) {
var tcpEndpoint = {hostname: 'localhost', port: 1113};
test.expect(1);
var tcpEndpoint = {host: '192.168.33.10', port: 1113};
var conn = client.EventStoreConnection.create(testBase.settings(), tcpEndpoint);
conn.connect()
.catch(function(err) {
@ -24,7 +25,8 @@ module.exports = {
}
},
'Connect To Endpoint That Doesn\'t Exist': function(test) {
var tcpEndpoint = {hostname: 'localhost', port: 11112};
test.expect(1);
var tcpEndpoint = {host: 'localhost', port: 11112};
var conn = client.EventStoreConnection.create(testBase.settings({maxReconnections:1}), tcpEndpoint);
conn.connect()
.catch(function (err) {
@ -43,16 +45,16 @@ module.exports = {
});
},
'Create a connection with tcp://host:port string': function(test) {
var conn = client.createConnection({}, 'tcp://localhost:2113');
var conn = client.createConnection({}, 'tcp://192.168.33.10:1113');
conn.close();
test.done();
}/*,
'Connect to Cluster using gossip seeds': function (test) {
test.expect(1);
var gossipSeeds = [
new GossipSeed({hostname: 'localhost', port: 1113}),
new GossipSeed({hostname: 'localhost', port: 2113}),
new GossipSeed({hostname: 'localhost', port: 3113})
new GossipSeed({host: 'localhost', port: 1113}),
new GossipSeed({host: 'localhost', port: 2113}),
new GossipSeed({host: 'localhost', port: 3113})
];
var conn = client.EventStoreConnection.create(testBase.settings(), gossipSeeds);
conn.connect()

View File

@ -14,6 +14,7 @@ module.exports = {
.catch(cb);
},
'Test Delete Stream Soft Happy Path': function(test) {
test.expect(4);
var self = this;
this.conn.deleteStream(this.testStreamName, 1, false)
.then(function(result) {
@ -31,6 +32,7 @@ module.exports = {
});
},
'Test Delete Stream Hard Happy Path': function(test) {
test.expect(4);
var self = this;
this.conn.deleteStream(this.testStreamName, 1, true)
.then(function(result) {
@ -48,6 +50,7 @@ module.exports = {
});
},
'Test Delete Stream With Wrong Expected Version': function(test) {
test.expect(1);
this.conn.deleteStream(this.testStreamName, 10)
.then(function(result) {
test.fail("Delete succeeded but should have failed.");
@ -61,6 +64,7 @@ module.exports = {
});
},
'Test Delete Stream With No Access': function(test) {
test.expect(1);
var self = this;
this.conn.setStreamMetadataRaw(this.testStreamName, client.expectedVersion.any, {$acl: {$d: "$admins"}})
.then(function() {
@ -78,6 +82,7 @@ module.exports = {
});
},
'Test Delete Stream Hard When Already Deleted': function(test) {
test.expect(1);
var self = this;
this.conn.deleteStream(this.testStreamName, 1, true)
.then(function() {

View File

@ -22,14 +22,26 @@ module.exports = {
},
//TODO: Update Persistent Subscription
'Test ConnectTo Persistent Subscription': function(test) {
test.expect(2);
var _doneCount = 0;
function done(err) {
test.ok(!err, err ? err.stack : '');
_doneCount++;
if (_doneCount < 2) return;
test.done();
}
function eventAppeared(s, e) {
s.stop();
}
function subscriptionDropped(connection, reason, error) {
test.done(error);
done(error);
}
var subscription = this.conn.connectToPersistentSubscription(testStreamName, 'consumer-1', eventAppeared, subscriptionDropped);
this.conn.appendToStream(testStreamName, client.expectedVersion.any, [createRandomEvent()]);
this.conn.appendToStream(testStreamName, client.expectedVersion.any, [createRandomEvent()])
.then(function () {
done();
})
.catch(done);
},
'Test Delete Persistent Subscription': function(test) {
this.conn.deletePersistentSubscription(testStreamName, 'consumer-1', adminCredentials)

View File

@ -37,6 +37,7 @@ module.exports = {
})
},
'Read All Events Backward Happy Path': function(test) {
test.expect(4 + maxCount);
var self = this;
this.conn.readAllEventsBackward(client.positions.end, maxCount, false, allCredentials)
.then(function(slice) {
@ -56,6 +57,7 @@ module.exports = {
})
},
'Read All Events Backward With No Access': function(test) {
test.expect(1);
this.conn.readAllEventsBackward(client.positions.end, maxCount)
.then(function(slice) {
test.fail("readAllEventsBackward succeeded but should have failed.");

View File

@ -37,6 +37,7 @@ module.exports = {
})
},
'Read All Events Forward Happy Path': function(test) {
test.expect(5 + maxCount);
this.conn.readAllEventsForward(client.positions.start, maxCount, false, allCredentials)
.then(function(slice) {
test.areEqual('slice.readDirection', slice.readDirection, 'forward');
@ -57,6 +58,7 @@ module.exports = {
})
},
'Read All Events Forward With No Access': function(test) {
test.expect(1);
this.conn.readAllEventsForward(client.positions.start, maxCount)
.then(function(slice) {
test.fail("readAllEventsForward succeeded but should have failed.");

View File

@ -16,6 +16,7 @@ module.exports = {
.catch(cb);
},
'Read Event Happy Path': function(test) {
test.expect(8);
var self = this;
this.conn.readEvent(this.testStreamName, 0)
.then(function(result) {
@ -35,6 +36,7 @@ module.exports = {
})
},
'Read Event From Non-Existing Stream': function(test) {
test.expect(4);
var anotherStream = 'test' + uuid.v4();
this.conn.readEvent(anotherStream, 0)
.then(function(result) {
@ -49,6 +51,7 @@ module.exports = {
});
},
'Read Event From Deleted Stream': function(test) {
test.expect(4);
var self = this;
this.conn.deleteStream(this.testStreamName, 0, true)
.then(function() {
@ -66,6 +69,7 @@ module.exports = {
});
},
'Read Event With Inexisting Version': function(test) {
test.expect(4);
var self = this;
return self.conn.readEvent(self.testStreamName, 1)
.then(function(result) {
@ -80,6 +84,7 @@ module.exports = {
});
},
'Read Event With No Access': function(test) {
test.expect(1);
var self = this;
var metadata = {$acl: {$r: '$admins'}};
this.conn.setStreamMetadataRaw(self.testStreamName, client.expectedVersion.noStream, metadata)

View File

@ -16,6 +16,7 @@ module.exports = {
.catch(cb);
},
'Read Stream Events Backward Happy Path': function(test) {
test.expect(7 + (streamSize * 6));
var self = this;
this.conn.readStreamEventsBackward(this.testStreamName, streamSize-1, streamSize)
.then(function(slice) {
@ -38,6 +39,7 @@ module.exports = {
})
},
'Read Stream Events Backward With Non-Existing Stream': function(test) {
test.expect(4);
var anotherStream = 'test' + uuid.v4();
this.conn.readStreamEventsBackward(anotherStream, streamSize-1, streamSize)
.then(function(slice) {
@ -52,6 +54,7 @@ module.exports = {
});
},
'Read Stream Events Backward With Deleted Stream': function(test) {
test.expect(4);
var self = this;
this.conn.deleteStream(this.testStreamName, streamSize-1, true)
.then(function() {
@ -69,6 +72,7 @@ module.exports = {
});
},
'Read Stream Events Backward With Inexisting Version': function(test) {
test.expect(4);
var self = this;
return self.conn.readStreamEventsBackward(self.testStreamName, streamSize * 2, streamSize)
.then(function(slice) {
@ -83,6 +87,7 @@ module.exports = {
});
},
'Read Stream Events Backward With No Access': function(test) {
test.expect(1);
var self = this;
var metadata = {$acl: {$r: '$admins'}};
this.conn.setStreamMetadataRaw(self.testStreamName, client.expectedVersion.noStream, metadata)

View File

@ -16,6 +16,7 @@ module.exports = {
.catch(cb);
},
'Read Stream Events Forward Happy Path': function(test) {
test.expect(7 + (streamSize * 6));
var self = this;
this.conn.readStreamEventsForward(this.testStreamName, 0, streamSize)
.then(function(slice) {
@ -37,6 +38,7 @@ module.exports = {
})
},
'Read Stream Events Forward With Non-Existing Stream': function(test) {
test.expect(4);
var anotherStream = 'test' + uuid.v4();
this.conn.readStreamEventsForward(anotherStream, 0, streamSize)
.then(function(slice) {
@ -51,6 +53,7 @@ module.exports = {
});
},
'Read Stream Events Forward With Deleted Stream': function(test) {
test.expect(4);
var self = this;
this.conn.deleteStream(this.testStreamName, streamSize-1, true)
.then(function() {
@ -68,6 +71,7 @@ module.exports = {
});
},
'Read Stream Events Forward With Inexisting Version': function(test) {
test.expect(4);
var self = this;
return self.conn.readStreamEventsForward(self.testStreamName, streamSize * 2, streamSize)
.then(function(slice) {
@ -82,6 +86,7 @@ module.exports = {
});
},
'Read Stream Events Forward With No Access': function(test) {
test.expect(1);
var self = this;
var metadata = {$acl: {$r: '$admins'}};
this.conn.setStreamMetadataRaw(self.testStreamName, client.expectedVersion.noStream, metadata)

View File

@ -9,10 +9,18 @@ function createRandomEvent() {
module.exports = {
'Test Subscribe to All From': function(test) {
test.expect(4);
var self = this;
var liveProcessing = false;
var catchUpEvents = [];
var liveEvents = [];
var _doneCount = 0;
function done(err) {
test.ok(!err, err ? err.stack : '');
_doneCount++;
if (_doneCount < 2) return;
test.done();
}
function eventAppeared(s, e) {
if (liveProcessing) {
liveEvents.push(e);
@ -24,12 +32,16 @@ module.exports = {
function liveProcessingStarted() {
liveProcessing = true;
var events = [createRandomEvent()];
self.conn.appendToStream(self.testStreamName, client.expectedVersion.any, events);
self.conn.appendToStream(self.testStreamName, client.expectedVersion.any, events)
.then(function () {
done();
})
.catch(done);
}
function subscriptionDropped(connection, reason, error) {
test.ok(liveEvents.length === 1, "Expecting 1 live event, got " + liveEvents.length);
test.ok(catchUpEvents.length > 1, "Expecting at least 1 catchUp event, got " + catchUpEvents.length);
test.done(error);
done(error);
}
var subscription = this.conn.subscribeToAllFrom(null, false, eventAppeared, liveProcessingStarted, subscriptionDropped, allCredentials);
}

View File

@ -6,6 +6,15 @@ module.exports = {
'Test Subscribe To All Happy Path': function(test) {
const resolveLinkTos = false;
const numberOfPublishedEvents = 5;
test.expect(numberOfPublishedEvents + 4);
var _doneCount = 0;
function done(err) {
test.ok(!err, err ? err.stack : '');
if (++_doneCount < 2) return;
test.done();
}
var publishedEvents = [];
for(var i=0;i<numberOfPublishedEvents;i++)
publishedEvents.push(client.createJsonEventData(uuid.v4(), {a: Math.random(), b: uuid.v4()}, null, 'anEvent'));
@ -25,10 +34,10 @@ module.exports = {
if (receivedEvents.length === numberOfPublishedEvents) subscription.close();
}
function subscriptionDropped(subscription, reason, error) {
if (error) return test.done(error);
if (error) return done(error);
testAllPublishedEventsAppeared();
testEventsAppearedInCorrectOrder();
test.done();
done();
}
var self = this;
this.conn.subscribeToAll(resolveLinkTos, eventAppeared, subscriptionDropped, allCredentials)
@ -37,6 +46,9 @@ module.exports = {
return self.conn.appendToStream(self.testStreamName, client.expectedVersion.emptyStream, publishedEvents);
})
.then(function () {
done();
})
.catch(test.done)
}
};

View File

@ -8,10 +8,19 @@ function createRandomEvent() {
module.exports = {
'Test Subscribe to Stream From Happy Path': function(test) {
test.expect(8);
var self = this;
var liveProcessing = false;
var catchUpEvents = [];
var liveEvents = [];
var _doneCount = 0;
function done(err) {
test.ok(!err, err ? err.stack : '');
if (++_doneCount < 2) return;
test.done();
}
function eventAppeared(s, e) {
if (liveProcessing) {
liveEvents.push(e);
@ -23,12 +32,16 @@ module.exports = {
function liveProcessingStarted() {
liveProcessing = true;
var events = [createRandomEvent()];
self.conn.appendToStream(self.testStreamName, client.expectedVersion.any, events);
self.conn.appendToStream(self.testStreamName, client.expectedVersion.any, events)
.then(function () {
done();
})
.catch(done);
}
function subscriptionDropped(connection, reason, error) {
test.ok(liveEvents.length === 1, "Expecting 1 live event, got " + liveEvents.length);
test.ok(catchUpEvents.length >= 1, "Expecting at least 1 catchUp event, got " + catchUpEvents.length);
test.done(error);
done(error);
}
var events = [createRandomEvent()];
@ -40,7 +53,8 @@ module.exports = {
test.areEqual("subscription.isSubscribedToAll", subscription.isSubscribedToAll, false);
test.areEqual("subscription.readBatchSize", subscription.readBatchSize, 500);
test.areEqual("subscription.maxPushQueueSize", subscription.maxPushQueueSize, 10000);
});
})
.catch(test.done);
}
};

View File

@ -5,10 +5,18 @@ module.exports = {
'Test Subscribe To Stream Happy Path': function(test) {
const resolveLinkTos = false;
const numberOfPublishedEvents = 5;
test.expect(numberOfPublishedEvents + 6);
var publishedEvents = [];
for(var i=0;i<numberOfPublishedEvents;i++)
publishedEvents.push(client.createJsonEventData(uuid.v4(), {a: Math.random(), b: uuid.v4()}, null, 'anEvent'));
var _doneCount = 0;
function done(err) {
test.ok(!err, err ? err.stack : '');
if (++_doneCount < 2) return;
test.done();
}
function testAllPublishedEventsAppeared() {
test.areEqual("receivedEvents.length", receivedEvents.length, numberOfPublishedEvents);
}
@ -24,10 +32,10 @@ module.exports = {
if (receivedEvents.length === numberOfPublishedEvents) subscription.close();
}
function subscriptionDropped(subscription, reason, error) {
if (error) return test.done(error);
if (error) return done(error);
testAllPublishedEventsAppeared();
testEventsAppearedInCorrectOrder();
test.done();
done();
}
var self = this;
this.conn.subscribeToStream(this.testStreamName, resolveLinkTos, eventAppeared, subscriptionDropped)
@ -38,6 +46,9 @@ module.exports = {
return self.conn.appendToStream(self.testStreamName, client.expectedVersion.emptyStream, publishedEvents);
})
.then(function () {
done();
})
.catch(test.done)
}
};

View File

@ -7,6 +7,7 @@ module.exports = {
cb();
},
'Start A Transaction Happy Path': function(test) {
test.expect(1);
this.conn.startTransaction(this.testStreamName, client.expectedVersion.noStream)
.then(function(trx) {
test.ok(Long.isLong(trx.transactionId), "trx.transactionId should be a Long.");
@ -46,6 +47,7 @@ module.exports = {
},
*/
'Start A Transaction With No Access': function(test) {
test.expect(1);
var self = this;
var metadata = {$acl: {$w: "$admins"}};
this.conn.setStreamMetadataRaw(this.testStreamName, -1, metadata)
@ -84,6 +86,7 @@ module.exports = {
.catch(test.done);
},
'Write/Commit Transaction Happy Path': function(test) {
test.expect(2);
var self = this;
this.conn.startTransaction(this.testStreamName, client.expectedVersion.emptyStream)
.then(function(trx) {
@ -114,6 +117,7 @@ module.exports = {
.catch(test.done);
},
'Write/Commit Transaction With Wrong Expected Version': function(test) {
test.expect(1);
this.conn.startTransaction(this.testStreamName, 10)
.then(function(trx) {
return trx.write(client.createJsonEventData(uuid.v4(), {a: Math.random(), b: uuid.v4()}, null, 'anEvent'))
@ -133,6 +137,7 @@ module.exports = {
});
},
'Write/Commit Transaction With Deleted Stream': function(test) {
test.expect(1);
var self = this;
this.conn.deleteStream(this.testStreamName, client.expectedVersion.emptyStream, true)
.then(function() {
@ -156,6 +161,7 @@ module.exports = {
});
},
'Write/Commit Transaction With No Write Access': function(test) {
test.expect(1);
var self = this;
this.conn.startTransaction(this.testStreamName, client.expectedVersion.any)
.then(function(trx) {