-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventProcessor.js
230 lines (159 loc) · 5.41 KB
/
EventProcessor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/**
* Created by Luís A. Bastião Silva <[email protected]> on 06/04/15.
*/
import {Configs} from './configs';
console.log("Require Socket IO");
var io = require('socket.io-client');
import {fsm} from './handlers/ClientStateMachine';
class EventProcessor {
constructor(EsgrimaInstance) {
this.EsgrimaInstance = EsgrimaInstance;
this.testSuiteList = EsgrimaInstance.getTests();
this.groupName = EsgrimaInstance.getMyGroup();
this.reportedTest = {};
this.stopTestsNOW = false;
}
start() {
// on /start
console.log("EventProcessor: start connecting");
this.controller = io.connect(Configs.wsUrl);
var controller = this.controller;
this.controller.on('connect', function (data) {
console.log("The client is now starting with");
});
this.controller.on('startTests', function (data) {
console.log("Tests are starting");
fsm.startTests();
//controller.emit('ready');
});
var self = this;
this.controller.on('stopTests', function (data) {
console.log("Reset the state machine.");
console.log("No more tests available!!");
console.log(data);
self.stopTestsNOW = true;
if (data!==undefined && data.force)
{
console.log("stopTests force");
setTimeout(function () {
fsm.stopTests().then(function ()
{
self.stopTestsNOW = false;
fsm.startTests();
}).catch(function (err) {
console.log(err);
});
},100);
}
else
{
console.log("stopTests without force");
fsm.stopTests()
}
});
this.controller.on('disconnect', function (data) {
});
this.controller.on('reconnect', function (data) {
});
console.log("This is my group:");
console.log(this.groupName);
this.group = io.connect(Configs.wsUrl+this.groupName);
var group = this.group;
var self = this;
this.group.on('connect', function (data) {
//group.emit('ready');
console.log("New connection in " + self.groupName);
});
this.group.on('executeTn', function (data) {
// Start Executing the tests.
// Id of tests is: data.id
console.log("Execute a test, TN");
console.log(data);
fsm.executeTn(data);
});
this.group.on('disconnect', function (data) {
// TODO: handle that in future
console.log("Disconnecting-.-");
});
this.group.on('reconnect', function (data) {
// TODO: handle that in future
console.log("Reconnect-.-");
});
}
isToStopTests()
{
return this.stopTestsNOW;
}
ready() {
console.log("fsm.current");
console.log(fsm.current);
fsm.readyToRun().catch(function (err) {
console.log(err);
});
}
emitsReadyToRun(){
this.controller.emit('ready');
}
stopTests()
{
this.controller.emit('stoppedTests');
}
report(id, report)
{
fsm.reportTn(id);
//Send the reports back.
console.log("######### Emiting reportTn from " + id);
this.group.emit('reportTn', report);
}
sendReport()
{
this.report(this.executedTest, this.reportedTest)
}
preExecuteTest(id) {
this.executedTest = id;
console.log("Executing test number: " + id);
// The code to execute the test
}
executeTest()
{
//EventProcessorInstance.sendReport();
console.log(this.executedTest);
var testToExecute = this.EsgrimaInstance.getTestByName(this.executedTest);
var self = this;
this.reportedTest = {"id": self.executedTest};
console.log(testToExecute);
var linkToFunction = testToExecute.args.callBackResult;
if (testToExecute.args.originalCallBackResult===undefined)
{
testToExecute.args.originalCallBackResult = linkToFunction;
}
var linkToExec = testToExecute.args.originalCallBackResult;
var callBackResultDemo = function(){
console.log("Finishing the operation!!! ");
self.report(self.executedTest, self.reportedTest)
linkToExec();
} ;
testToExecute.args.callBackResult = callBackResultDemo;
//testToExecute.callbackOfTests(testToExecute.args);
try{
testToExecute.callbackOfTests(testToExecute.args);
}catch (err)
{
console.log(err);
self.reportedTest = {'error': JSON.stringify(err)} ;
testToExecute.args.callBackResult();
//throw err;
}
//this.reportedTest = {};
}
executedTest(id, reports,assertations)
{
// The code to executed the test
// TODO: more complex to implement (future)
}
getSocket()
{
return this.socket;
}
}
export {EventProcessor}