forked from robtweed/qewd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- fix issue with microservice router for koa
- add resilient mode test
- Loading branch information
Showing
11 changed files
with
203 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
|
||
handlers: { | ||
test: function (messageObj, session, send, finished) { | ||
const incomingText = messageObj.params.text; | ||
|
||
finished({ | ||
text: `You sent: ${incomingText} via express` | ||
}); | ||
} | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
const qewd = require('qewd').master; | ||
const path = require('path'); | ||
const utils = require('../utils'); | ||
|
||
const xp = qewd.intercept(); | ||
const q = xp.q; | ||
|
||
q.on('start', function () { | ||
this.worker.loaderFilePath = path.join(__dirname, '../../..', 'node_modules/ewd-qoper8-worker.js'); | ||
}); | ||
|
||
q.on('started', function () { | ||
process.send({ | ||
type: 'qewd:started' | ||
}); | ||
}); | ||
|
||
const config = { | ||
managementPassword: 'keepThisSecret!', | ||
serverName: 'New QEWD Server', | ||
webServer: utils.webServer(), | ||
port: 8080, | ||
poolSize: 2, | ||
database: utils.db(), | ||
resilientMode: true, | ||
moduleMap: { | ||
'test-app': path.join(__dirname, 'handlers/test-app') | ||
} | ||
}; | ||
qewd.start(config); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
'use strict'; | ||
|
||
const request = require('supertest')('http://localhost:8080'); | ||
const io = require('socket.io-client'); | ||
const isUUID = require('is-uuid'); | ||
const utils = require('../utils'); | ||
|
||
describe('integration/qewd/resilient-mode:', () => { | ||
let cp; | ||
|
||
const options = { | ||
cwd: __dirname | ||
}; | ||
|
||
beforeAll((done) => { | ||
cp = utils.fork('./qewd', options, done); | ||
}); | ||
|
||
afterAll((done) => { | ||
utils.exit(cp, done); | ||
}); | ||
|
||
describe('register', () => { | ||
let data; | ||
|
||
beforeEach(() => { | ||
data = { | ||
type: 'ewd-register', | ||
application: 'test-app' | ||
}; | ||
}); | ||
|
||
it('should be able to register app using websockets', (done) => { | ||
const socket = io.connect('ws://localhost:8080'); | ||
|
||
socket.on('connect', () => socket.emit('ewdjs', data)); | ||
socket.on('ewdjs', (responseObj) => { | ||
socket.disconnect(); | ||
|
||
expect(responseObj).toEqual({ | ||
type: 'ewd-register', | ||
finished: true, | ||
message: { | ||
token: jasmine.any(String) | ||
}, | ||
responseTime: jasmine.stringMatching(/^\d*ms$/) | ||
}); | ||
expect(isUUID.v4(responseObj.message.token)).toBeTruthy(); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('reregister', () => { | ||
let data; | ||
|
||
beforeEach((done) => { | ||
request. | ||
post('/ajax'). | ||
send({ | ||
type: 'ewd-register', | ||
application: 'test-app' | ||
}). | ||
end((err, res) => { | ||
if (err) return done.fail(err); | ||
|
||
data = { | ||
type: 'ewd-reregister', | ||
token: res.body.token | ||
}; | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
it('should be able to reregister app using websockets', (done) => { | ||
const socket = io.connect('ws://localhost:8080'); | ||
|
||
socket.on('connect', () => socket.emit('ewdjs', data)); | ||
socket.on('ewdjs', (responseObj) => { | ||
socket.disconnect(); | ||
|
||
expect(responseObj).toEqual({ | ||
type: 'ewd-reregister', | ||
finished: true, | ||
message: { | ||
ok: true | ||
}, | ||
responseTime: jasmine.stringMatching(/^\d*ms$/) | ||
}); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('custom message', () => { | ||
let data; | ||
|
||
beforeEach((done) => { | ||
request. | ||
post('/ajax'). | ||
send({ | ||
type: 'ewd-register', | ||
application: 'test-app' | ||
}). | ||
end((err, res) => { | ||
if (err) return done.fail(err); | ||
|
||
data = { | ||
type: 'test', | ||
token: res.body.token, | ||
params: { | ||
text: 'Hello world' | ||
} | ||
}; | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
it('should be able to send message using websockets', (done) => { | ||
const socket = io.connect('ws://localhost:8080'); | ||
|
||
socket.on('connect', () => socket.emit('ewdjs', data)); | ||
socket.on('ewdjs', (responseObj) => { | ||
socket.disconnect(); | ||
|
||
expect(responseObj).toEqual({ | ||
type: 'test', | ||
finished: true, | ||
message: { | ||
text: 'You sent: Hello world via express' | ||
}, | ||
responseTime: jasmine.stringMatching(/^\d*ms$/) | ||
}); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>It Works</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters