Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.30 KB | None | 0 0
  1. import * as fs from 'fs';
  2. import * as util from 'util';
  3.  
  4. import { EventTimestamp } from './eventTimestamp';
  5. import { Counts, SubCounts } from './genericCounts';
  6. import { checkTestIntegrity } from './integrityCheck';
  7. import { EventType, ILogEvent } from './logEvent';
  8. import { info } from './logger';
  9. import { LogResults } from './logResults';
  10. import { INode, INodeMap } from './node';
  11. import { Pod } from './pod';
  12. import { TestConfig } from './testConfig';
  13. import { ITx, ITxMap } from './tx';
  14.  
  15. const localTestConfig = new TestConfig(60, 2, true, 1);
  16.  
  17. enum ValidatorType {
  18. CURRENT = 0,
  19. PREVIOUS = 1,
  20. SNAPSHOT = 2,
  21. }
  22.  
  23. enum LogType {
  24. FIREBASE = 0,
  25. WINSTON = 1,
  26. MONGODB = 2,
  27. }
  28.  
  29. const getGlobalResults = (): LogResults => globalResults;
  30. let startTime: number;
  31. let endTime: number;
  32. let expectedEndTime: number = Date.now() * 2;
  33. let globalResults = {} as LogResults;
  34.  
  35. const parseResults = (results: any, type: LogType, printResults: boolean): void => {
  36. type === LogType.WINSTON && (parseWinstonResults(results, printResults));
  37. type === LogType.FIREBASE && (parseFirebaseResults(results, printResults));
  38. type === LogType.MONGODB && (parseMongoDBResults(results, printResults));
  39. };
  40.  
  41. const parseWinstonResults = (results: any, printResults: boolean): void => {
  42. const firstEntry: ILogEvent = results.file[0];
  43. const lastEntry: ILogEvent = results.file[results.file.length - 1];
  44. startTime = Date.parse(<string>firstEntry.timestamp);
  45. endTime = Date.parse(<string>lastEntry.timestamp);
  46. parseCommonResults(results.file, printResults, startTime, endTime);
  47. };
  48.  
  49. const parseFirebaseResults = (results: any, printResults: boolean): void => {
  50. const keys = Object.keys(results);
  51. const firstEntry: ILogEvent = results[keys[0]];
  52. const lastEntry: ILogEvent = results[keys[keys.length - 1]];
  53. startTime = <number>firstEntry.timestamp;
  54. endTime = <number>lastEntry.timestamp;
  55. const resultArray = [];
  56. for (let i = 0; i < keys.length; i += 1) {
  57. const key = keys[i];
  58. resultArray.push(results[key]);
  59. }
  60. parseCommonResults(resultArray, printResults, startTime, endTime);
  61. };
  62.  
  63. const parseMongoDBResults = (results: any, printResults: boolean): void => {
  64. const firstEntry: ILogEvent = results[0];
  65. const lastEntry: ILogEvent = results[results.length - 1];
  66. startTime = <number>firstEntry.timestamp;
  67. endTime = <number>lastEntry.timestamp;
  68. info(`Log Start Time: ${startTime}`);
  69. info(`Log End Time: ${endTime}`);
  70. parseCommonResults(results, printResults, startTime, endTime);
  71. // const _results = JSON.parse(results);
  72. // const keys = Object.keys(_results);
  73. // const firstEntry: ILogEvent = _results[keys[0]];
  74. // const lastEntry: ILogEvent = _results[keys[keys.length - 1]];
  75. // startTime = <number>firstEntry.timestamp;
  76. // endTime = <number>lastEntry.timestamp;
  77. // const resultArray = [];
  78. // for (let i = 0; i < keys.length; i += 1) {
  79. // const key = keys[i];
  80. // resultArray.push(_results[key])
  81. // }
  82. // parseCommonResults(resultArray, printResults, startTime, endTime);
  83. };
  84.  
  85. const parseCommonResults = (results: any, printResults: boolean, startTime: number, endTime: number): void => {
  86. const txMap: ITxMap = {};
  87. const nodeMap: INodeMap = {};
  88. for (let i = 0; i < results.length; i += 1) {
  89. const result: ILogEvent = results[i];
  90. // console.dir(result);
  91. const {
  92. sender,
  93. receiver,
  94. connectionTo,
  95. owner,
  96. timestamp,
  97. transactionId,
  98. eventType,
  99. testConfig,
  100. }: ILogEvent = result;
  101. const nTimestamp: number = typeof timestamp === 'string' ? Date.parse(<string>timestamp) : timestamp;
  102. const tx = getTx(transactionId, txMap);
  103. const _sender = getNode(sender, nodeMap);
  104. const _receiver = getNode(receiver, nodeMap);
  105. const _owner = getNode(owner, nodeMap);
  106. const _connectionTo = getNode(connectionTo, nodeMap);
  107. if (eventType === EventType.TEST_START) {
  108. Object.assign(localTestConfig, testConfig);
  109. expectedEndTime = startTime + localTestConfig.duration;
  110. continue;
  111. }
  112. if (nTimestamp < expectedEndTime) {
  113. switch (eventType) {
  114. case EventType.TRANSACTION_START:
  115. tx.txData = {
  116. from: _sender.pod.address,
  117. to: _receiver.pod.address,
  118. };
  119. tx.transaction.lifetime.start = nTimestamp;
  120. break;
  121. case EventType.TRANSACTION_END:
  122. tx.transaction.lifetime.end = nTimestamp;
  123. _sender.counts.sender += 1;
  124. break;
  125. case EventType.REQUEST_VALIDATION_START:
  126. doesValidatorExist(_owner.pod.address, ValidatorType.CURRENT, tx);
  127. _owner.counts.currentValidator += 1;
  128. tx.currentValidators[_owner.pod.address].validation.lifetime.start = nTimestamp;
  129. tx.currentValidators[_owner.pod.address].validation.requestValidation.start = nTimestamp;
  130. break;
  131. case EventType.REQUEST_VALIDATION_END:
  132. doesValidatorExist(_owner.pod.address, ValidatorType.CURRENT, tx);
  133. tx.currentValidators[_owner.pod.address].validation.lifetime.end = nTimestamp;
  134. tx.currentValidators[_owner.pod.address].validation.requestValidation.end = nTimestamp;
  135. break;
  136. case EventType.CONNECT_TO_VALIDATOR_START:
  137. doesValidatorExist(_connectionTo.pod.address, ValidatorType.CURRENT, tx);
  138. tx.currentValidators[_connectionTo.pod.address].connection.start = nTimestamp;
  139. break;
  140. case EventType.CONNECT_TO_VALIDATOR_END:
  141. doesValidatorExist(_connectionTo.pod.address, ValidatorType.CURRENT, tx);
  142. tx.currentValidators[_connectionTo.pod.address].connection.end = nTimestamp;
  143. break;
  144. case EventType.CONNECT_TO_PREVIOUS_VALIDATOR_START:
  145. doesValidatorExist(_owner.pod.address, ValidatorType.CURRENT, tx, () => {
  146. doesValidatorExist(_connectionTo.pod.address, ValidatorType.PREVIOUS, tx, () => {
  147. tempDoesValidatorExist(_owner.pod.address, ValidatorType.PREVIOUS, _connectionTo.pod.address, tx);
  148. _connectionTo.counts.previousValidator += 1;
  149. tx.previousValidators[_connectionTo.pod.address].connection[_owner.pod.address].start = nTimestamp;
  150. });
  151. });
  152. break;
  153. case EventType.CONNECT_TO_PREVIOUS_VALIDATOR_END:
  154. doesValidatorExist(_owner.pod.address, ValidatorType.CURRENT, tx, () => {
  155. doesValidatorExist(_connectionTo.pod.address, ValidatorType.PREVIOUS, tx, () => {
  156. tempDoesValidatorExist(_owner.pod.address, ValidatorType.PREVIOUS, _connectionTo.pod.address, tx);
  157. tx.previousValidators[_connectionTo.pod.address].connection[_owner.pod.address].end = nTimestamp;
  158. });
  159. });
  160. break;
  161. case EventType.GENERATE_SIGNATURE_START:
  162. tx.transaction.generateSignature.start = nTimestamp;
  163. break;
  164. case EventType.GENERATE_SIGNATURE_END:
  165. tx.transaction.generateSignature.end = nTimestamp;
  166. break;
  167. case EventType.VALIDATE_SIGNATURE_START:
  168. doesValidatorExist(_owner.pod.address, ValidatorType.CURRENT, tx);
  169. tx.currentValidators[_owner.pod.address].validation.validateSignature.start = nTimestamp;
  170. break;
  171. case EventType.VALIDATE_SIGNATURE_END:
  172. doesValidatorExist(_owner.pod.address, ValidatorType.CURRENT, tx);
  173. tx.currentValidators[_owner.pod.address].validation.validateSignature.end = nTimestamp;
  174. break;
  175. case EventType.VALIDATE_LEDGER_START:
  176. doesValidatorExist(_owner.pod.address, ValidatorType.CURRENT, tx);
  177. tx.currentValidators[_owner.pod.address].validation.validateLedger.start = nTimestamp;
  178. break;
  179. case EventType.VALIDATE_LEDGER_END:
  180. doesValidatorExist(_owner.pod.address, ValidatorType.CURRENT, tx);
  181. tx.currentValidators[_owner.pod.address].validation.validateLedger.end = nTimestamp;
  182. break;
  183. case EventType.GET_ENTRY_FROM_LEDGER_START:
  184. doesValidatorExist(_owner.pod.address, ValidatorType.PREVIOUS, tx);
  185. tx.previousValidators[_owner.pod.address].validation.getEntryFromLedger.start = nTimestamp;
  186. break;
  187. case EventType.GET_ENTRY_FROM_LEDGER_END:
  188. doesValidatorExist(_owner.pod.address, ValidatorType.PREVIOUS, tx);
  189. tx.previousValidators[_owner.pod.address].validation.getEntryFromLedger.end = nTimestamp;
  190. break;
  191. case EventType.GENERATE_TRANSACTION_HASH_START:
  192. try {
  193. if (_owner.pod.address === _sender.pod.address) {
  194. tx.transaction.generateHash.start = nTimestamp;
  195. }
  196. else {
  197. doesValidatorExist(_owner.pod.address, ValidatorType.CURRENT, tx);
  198. tx.currentValidators[_owner.pod.address].validation.generateHash.start = nTimestamp;
  199. }
  200. } catch (error) {
  201. console.dir(result);
  202. console.log(error);
  203. }
  204. break;
  205. case EventType.GENERATE_TRANSACTION_HASH_END:
  206. if (_owner.pod.address === _sender.pod.address) {
  207. tx.transaction.generateHash.end = nTimestamp;
  208. }
  209. else {
  210. doesValidatorExist(_owner.pod.address, ValidatorType.CURRENT, tx);
  211. tx.currentValidators[_owner.pod.address].validation.generateHash.end = nTimestamp;
  212. }
  213. break;
  214. case EventType.WRITE_TO_MY_LEDGER_START:
  215. tx.transaction.writeToMyLedger.start = nTimestamp;
  216. break;
  217. case EventType.WRITE_TO_MY_LEDGER_END:
  218. tx.transaction.writeToMyLedger.end = nTimestamp;
  219. break;
  220. case EventType.WRITE_TO_WITNESS_LEDGER_START:
  221. doesValidatorExist(_owner.pod.address, ValidatorType.CURRENT, tx);
  222. tx.currentValidators[_owner.pod.address].validation.writeToWitnessLedger.start = nTimestamp;
  223. break;
  224. case EventType.WRITE_TO_WITNESS_LEDGER_END:
  225. doesValidatorExist(_owner.pod.address, ValidatorType.CURRENT, tx);
  226. tx.currentValidators[_owner.pod.address].validation.writeToWitnessLedger.end = nTimestamp;
  227. break;
  228. case EventType.CONNECT_TO_SNAPSHOT_NODE_START:
  229. doesValidatorExist(_owner.pod.address, ValidatorType.CURRENT, tx, () => {
  230. doesValidatorExist(_connectionTo.pod.address, ValidatorType.SNAPSHOT, tx, () => {
  231. tempDoesValidatorExist(_owner.pod.address, ValidatorType.SNAPSHOT, _connectionTo.pod.address, tx);
  232. _connectionTo.counts.snapshotValidator += 1;
  233. tx.snapshotValidators[_connectionTo.pod.address].connection[_owner.pod.address].start = nTimestamp;
  234. });
  235. });
  236. break;
  237. case EventType.CONNECT_TO_SNAPSHOT_NODE_END:
  238. doesValidatorExist(_owner.pod.address, ValidatorType.CURRENT, tx, () => {
  239. doesValidatorExist(_connectionTo.pod.address, ValidatorType.SNAPSHOT, tx, () => {
  240. tempDoesValidatorExist(_owner.pod.address, ValidatorType.SNAPSHOT, _connectionTo.pod.address, tx);
  241. tx.snapshotValidators[_connectionTo.pod.address].connection[_owner.pod.address].end = nTimestamp;
  242. });
  243. });
  244. break;
  245. default:
  246. break;
  247. }
  248. }
  249. if (i === results.length - 1) {
  250. const keys = Object.keys(txMap);
  251. const randomNumber = Math.floor(Math.random() * (keys.length));
  252. const key = keys[randomNumber];
  253. const randomTx = txMap[key];
  254. const entries = (<any>Object).entries(txMap);
  255. setAllDiffs(entries);
  256. populateNodePerformance(txMap, nodeMap, (newTxMap, newPodMap) => {
  257. calculateNodePerformance(newTxMap, newPodMap);
  258. });
  259. checkTestIntegrity(results, txMap, nodeMap, localTestConfig, startTime, endTime, (result) => {
  260. if (result) {
  261. getResults(txMap, nodeMap, localTestConfig, printResults);
  262. }
  263. else {
  264. console.log('Log failed integrity check. Add messages.');
  265. }
  266. });
  267. console.log(key);
  268. console.log(util.inspect(randomTx, false, null));
  269. // console.dir(nodeMap);
  270. }
  271. }
  272. };
  273.  
  274. const populateNodePerformance = (txMap: ITxMap, nodeMap: INodeMap, callback: (txMap: ITxMap, nodeMap: INodeMap) => void) => {
  275. const keys = Object.keys(txMap);
  276. for (let i = 0; i < keys.length; i += 1) {
  277. const key = keys[i];
  278. const tx = txMap[key];
  279. const cvKeys = Object.keys(tx.currentValidators);
  280. for (let k = 0; k < cvKeys.length; k += 1) {
  281. const cvKey = cvKeys[k];
  282. const node = getNodeByAddress(cvKey, nodeMap);
  283. if (!node.transactions.hasOwnProperty(key)) {
  284. node.transactions[key] = {
  285. currentValidator: false,
  286. previousValidator: false,
  287. };
  288. }
  289. node.transactions[key].currentValidator = true;
  290. }
  291. const pvKeys = Object.keys(tx.previousValidators);
  292. for (let j = 0; j < pvKeys.length; j += 1) {
  293. const pvKey = pvKeys[j];
  294. const node = getNodeByAddress(pvKey, nodeMap);
  295. if (!node.transactions.hasOwnProperty(key)) {
  296. node.transactions[key] = {
  297. currentValidator: false,
  298. previousValidator: false,
  299. };
  300. }
  301. node.transactions[key].previousValidator = true;
  302. }
  303. }
  304. callback(txMap, nodeMap);
  305. };
  306.  
  307. const calculateNodePerformance = (txMap: ITxMap, nodeMap: INodeMap): void => {
  308. const keys = Object.keys(nodeMap);
  309. for (let i = 0; i < keys.length; i += 1) {
  310. const key = keys[i];
  311. const node = nodeMap[key];
  312. const txKeys = Object.keys(node.transactions);
  313. for (let k = 0; k < txKeys.length; k += 1) {
  314. const txKey = txKeys[k];
  315. const tx = txMap[txKey];
  316. const { txTimes, validationTimes, connectionTimes } = node.performance;
  317.  
  318. const txDiff = tx.transaction.lifetime.diff;
  319. txTimes.count += 1;
  320. if (txDiff !== undefined) {
  321. txTimes.total += txDiff;
  322. txDiff > txTimes.longest && (txTimes.longest = txDiff);
  323. txDiff < txTimes.shortest && (txTimes.shortest = txDiff);
  324. }
  325. else {
  326. txTimes.undef += 1;
  327. }
  328.  
  329. if (node.transactions[txKey].currentValidator) {
  330. const cv = tx.currentValidators[key];
  331. const cvValidDiff = cv.validation.lifetime.diff;
  332. validationTimes.count += 1;
  333. if (cvValidDiff !== undefined) {
  334. validationTimes.currentValidators.count += 1;
  335. validationTimes.total += cvValidDiff;
  336. validationTimes.currentValidators.total += cvValidDiff;
  337. cvValidDiff > validationTimes.currentValidators.longest && (validationTimes.currentValidators.longest = cvValidDiff);
  338. cvValidDiff < validationTimes.currentValidators.shortest && (validationTimes.currentValidators.shortest = cvValidDiff);
  339. }
  340. else {
  341. validationTimes.undef += 1;
  342. }
  343.  
  344. const cvConnDiff = cv.connection.diff;
  345. connectionTimes.count += 1;
  346. if (cvConnDiff !== undefined) {
  347. connectionTimes.currentValidators.count += 1;
  348. connectionTimes.total += cvConnDiff;
  349. connectionTimes.currentValidators.total += cvConnDiff;
  350. cvConnDiff > connectionTimes.currentValidators.longest && (connectionTimes.currentValidators.longest = cvConnDiff);
  351. cvConnDiff < connectionTimes.currentValidators.shortest && (connectionTimes.currentValidators.shortest = cvConnDiff);
  352. }
  353. else {
  354. connectionTimes.undef += 1;
  355. }
  356. }
  357. if (node.transactions[txKey].previousValidator) {
  358. const pv = tx.previousValidators[key];
  359. const pvValidDiff = pv.validation.lifetime.diff;
  360. validationTimes.count += 1;
  361. if (pvValidDiff !== undefined) {
  362. validationTimes.previousValidators.count += 1;
  363. validationTimes.total += pvValidDiff;
  364. validationTimes.previousValidators.total += pvValidDiff;
  365. pvValidDiff > validationTimes.previousValidators.longest && (validationTimes.previousValidators.longest = pvValidDiff);
  366. pvValidDiff < validationTimes.previousValidators.shortest && (validationTimes.previousValidators.shortest = pvValidDiff);
  367. }
  368. else {
  369. validationTimes.undef += 1;
  370. }
  371.  
  372. const pvConnKeys = Object.keys(pv.connection);
  373. for (let j = 0; j < pvConnKeys.length; j += 1) {
  374. const pvcKey = pvConnKeys[j];
  375. const pvc = pv.connection[pvcKey];
  376. const pvcDiff = pvc.diff;
  377. connectionTimes.count += 1;
  378. if (pvcDiff !== undefined) {
  379. connectionTimes.previousValidators.count += 1;
  380. connectionTimes.total += pvcDiff;
  381. connectionTimes.previousValidators.total += pvcDiff;
  382. pvcDiff > connectionTimes.previousValidators.longest && (connectionTimes.previousValidators.longest = pvcDiff);
  383. pvcDiff < connectionTimes.previousValidators.shortest && (connectionTimes.previousValidators.shortest = pvcDiff);
  384. }
  385. else {
  386. connectionTimes.undef += 1;
  387. }
  388. }
  389. }
  390. }
  391. }
  392. };
  393.  
  394. const setAllDiffs = (entries: [string, ITx][]) => {
  395. const readProp = (prop: any) => {
  396. const keys = Object.keys(prop);
  397. for (let i = 0; i < keys.length; i += 1) {
  398. const key = keys[i];
  399. const value = prop[key];
  400. if (value) {
  401. if (value.constructor.name === 'EventTimestamp') {
  402. if (value.end >= value.start) {
  403. value.diff = value.end - value.start;
  404. }
  405. }
  406. else {
  407. if (typeof value === 'object') {
  408. readProp(value);
  409. }
  410. }
  411. }
  412. }
  413. };
  414. for (const [, tx] of entries) {
  415. readProp(tx);
  416. }
  417. };
  418.  
  419. const getNode = (pod: Pod | undefined, nodeMap: INodeMap): INode => {
  420. let node = {} as INode;
  421. if (pod !== undefined) {
  422. if (!nodeMap.hasOwnProperty(pod.address)) {
  423. info('[getNode] Pod does not exist in nodeMap. Adding...');
  424. node = nodeMap[pod.address] = {
  425. pod,
  426. location: '',
  427. counts: {
  428. sender: 0,
  429. receiver: 0,
  430. currentValidator: 0,
  431. previousValidator: 0,
  432. },
  433. transactions: {},
  434. performance: {
  435. txTimes: new SubCounts(),
  436. validationTimes: new Counts(),
  437. connectionTimes: new Counts(),
  438. },
  439. };
  440. }
  441. else {
  442. info('[getNode] Pod already exists in nodeMap.');
  443. node = nodeMap[pod.address];
  444. }
  445. }
  446. else {
  447. console.log('Pod was undefined.');
  448. }
  449. return node;
  450. };
  451.  
  452. const getNodeByAddress = (address: string, nodeMap: INodeMap): INode => {
  453. let node = {} as INode;
  454. if (!nodeMap.hasOwnProperty(address)) {
  455. info(`[getNodeByAddress] Pod with address: ${address} does not exist in nodeMap.`);
  456. }
  457. else {
  458. info('[getNodeByAddress] Pod already exists in nodeMap.');
  459. node = nodeMap[address];
  460. }
  461. return node;
  462. };
  463.  
  464. const getTx = (transactionId: string, txMap: ITxMap): ITx => {
  465. let _tx = {} as ITx;
  466. if (!txMap.hasOwnProperty(transactionId)) {
  467. _tx = txMap[transactionId] = {
  468. txData: {
  469. from: '',
  470. to: '',
  471. },
  472. transaction: {
  473. lifetime: new EventTimestamp(0, 0),
  474. generateSignature: new EventTimestamp(0, 0),
  475. writeToMyLedger: new EventTimestamp(0, 0),
  476. generateHash: new EventTimestamp(0, 0),
  477. },
  478. currentValidators: {},
  479. previousValidators: {},
  480. snapshotValidators: {},
  481. };
  482. }
  483. else {
  484. _tx = txMap[transactionId];
  485. }
  486. return _tx;
  487. };
  488.  
  489. const tempDoesValidatorExist = (currentValidatorAddress: string, type: ValidatorType, validatorAddress: string, tx: ITx): void => {
  490. if (type === ValidatorType.PREVIOUS) {
  491. if (!tx.previousValidators[validatorAddress].connection.hasOwnProperty(currentValidatorAddress)) {
  492. tx.previousValidators[validatorAddress].connection[currentValidatorAddress] = new EventTimestamp(0, 0);
  493. }
  494. }
  495. if (type === ValidatorType.SNAPSHOT) {
  496. if (!tx.snapshotValidators[validatorAddress].connection.hasOwnProperty(currentValidatorAddress)) {
  497. tx.snapshotValidators[validatorAddress].connection[currentValidatorAddress] = new EventTimestamp(0, 0);
  498. }
  499. }
  500. };
  501.  
  502. const doesValidatorExist = (address: string, type: ValidatorType, tx: ITx, callback: () => void = () => {}): void => {
  503. if (type === ValidatorType.CURRENT) {
  504. if (!tx.currentValidators.hasOwnProperty(address)) {
  505. addValidatorToTx(address, type, tx, callback);
  506. }
  507. else {
  508. callback();
  509. }
  510. }
  511. if (type === ValidatorType.PREVIOUS) {
  512. if (!tx.previousValidators.hasOwnProperty(address)) {
  513. addValidatorToTx(address, type, tx, callback);
  514. }
  515. else {
  516. callback();
  517. }
  518. }
  519. if (type === ValidatorType.SNAPSHOT) {
  520. if (!tx.snapshotValidators.hasOwnProperty(address)) {
  521. addValidatorToTx(address, type, tx, callback);
  522. }
  523. else {
  524. callback();
  525. }
  526. }
  527. };
  528.  
  529. const addValidatorToTx = (address: string, type: ValidatorType, tx: ITx, callback: () => void = () => { }): ITx => {
  530. const currentValidatorObj = {
  531. validation: {
  532. lifetime: new EventTimestamp(0, 0),
  533. requestValidation: new EventTimestamp(0, 0),
  534. validateSignature: new EventTimestamp(0, 0),
  535. validateLedger: new EventTimestamp(0, 0),
  536. generateHash: new EventTimestamp(0, 0),
  537. writeToWitnessLedger: new EventTimestamp(0, 0),
  538. },
  539. connection: new EventTimestamp(0, 0),
  540. };
  541. const previousValidatorObj = {
  542. validation: {
  543. lifetime: new EventTimestamp(0, 0),
  544. getEntryFromLedger: new EventTimestamp(0, 0),
  545. },
  546. connection: {},
  547. };
  548. const snapshotValidatorObj = {
  549. validation: {
  550. generateSnapshot: new EventTimestamp(0, 0),
  551. },
  552. connection: {},
  553. };
  554.  
  555. if (type === ValidatorType.CURRENT) {
  556. tx.currentValidators[address] = currentValidatorObj;
  557. }
  558.  
  559. if (type === ValidatorType.PREVIOUS) {
  560. tx.previousValidators[address] = previousValidatorObj;
  561. }
  562.  
  563. if (type === ValidatorType.SNAPSHOT) {
  564. tx.snapshotValidators[address] = snapshotValidatorObj;
  565. }
  566. callback();
  567. return tx;
  568. };
  569.  
  570. const getResults = (txMap: ITxMap, nodeMap: INodeMap, testConfig: TestConfig, printResults: boolean): LogResults | void => {
  571. const results = new LogResults(txMap, nodeMap, testConfig);
  572. results.numTxs = Object.keys(txMap).length;
  573.  
  574. const regularPodCount = Object.keys(nodeMap).filter(key => nodeMap[key].pod.podType === 0).length;
  575. const partnerPodCount = Object.keys(nodeMap).filter(key => nodeMap[key].pod.podType === 1).length;
  576.  
  577. results.numPods = {
  578. total: Object.keys(nodeMap).length,
  579. regular: regularPodCount,
  580. partner: partnerPodCount,
  581. sender: testConfig.numSenders,
  582. };
  583.  
  584. results.duration = endTime - startTime;
  585. results.setTimes();
  586.  
  587. globalResults = results;
  588. fs.writeFileSync('results.json', JSON.stringify(results, null, 2));
  589. if (printResults) {
  590. results.printResults();
  591. }
  592. else {
  593. return results;
  594. }
  595. };
  596.  
  597. export { getGlobalResults, LogType, parseResults };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement