@axinom/mosaic-testing 0.7.16-rc.4 → 0.7.16-rc.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/dist/cjs/index.d.ts +2 -0
  2. package/dist/{index.d.ts.map → cjs/index.d.ts.map} +1 -1
  3. package/dist/{index.js → cjs/index.js} +1 -1
  4. package/dist/cjs/index.js.map +1 -0
  5. package/dist/cjs/package.json +1 -0
  6. package/dist/cjs/performance/index.d.ts +3 -0
  7. package/dist/cjs/performance/index.d.ts.map +1 -0
  8. package/dist/{performance → cjs/performance}/index.js +2 -2
  9. package/dist/cjs/performance/index.js.map +1 -0
  10. package/dist/{performance → cjs/performance}/plugins/inbox-outbox-report-endpoint-plugin.d.ts +2 -2
  11. package/dist/cjs/performance/plugins/inbox-outbox-report-endpoint-plugin.d.ts.map +1 -0
  12. package/dist/{performance → cjs/performance}/plugins/inbox-outbox-report-endpoint-plugin.js +9 -8
  13. package/dist/cjs/performance/plugins/inbox-outbox-report-endpoint-plugin.js.map +1 -0
  14. package/dist/{performance → cjs/performance}/plugins/inbox-outbox-state-endpoint-plugin.d.ts +2 -2
  15. package/dist/cjs/performance/plugins/inbox-outbox-state-endpoint-plugin.d.ts.map +1 -0
  16. package/dist/{performance → cjs/performance}/plugins/inbox-outbox-state-endpoint-plugin.js +4 -3
  17. package/dist/cjs/performance/plugins/inbox-outbox-state-endpoint-plugin.js.map +1 -0
  18. package/dist/cjs/performance/plugins/index.d.ts +3 -0
  19. package/dist/cjs/performance/plugins/index.d.ts.map +1 -0
  20. package/dist/{performance → cjs/performance}/plugins/index.js +4 -4
  21. package/dist/cjs/performance/plugins/index.js.map +1 -0
  22. package/dist/cjs/performance/scripts/index.d.ts +4 -0
  23. package/dist/cjs/performance/scripts/index.d.ts.map +1 -0
  24. package/dist/{performance → cjs/performance}/scripts/index.js +3 -3
  25. package/dist/cjs/performance/scripts/index.js.map +1 -0
  26. package/dist/{performance → cjs/performance}/scripts/make-graphql-request.d.ts +2 -2
  27. package/dist/cjs/performance/scripts/make-graphql-request.d.ts.map +1 -0
  28. package/dist/{performance → cjs/performance}/scripts/make-graphql-request.js +2 -2
  29. package/dist/cjs/performance/scripts/make-graphql-request.js.map +1 -0
  30. package/dist/{performance → cjs/performance}/scripts/run-inbox-outbox-scenario.d.ts +3 -3
  31. package/dist/cjs/performance/scripts/run-inbox-outbox-scenario.d.ts.map +1 -0
  32. package/dist/{performance → cjs/performance}/scripts/run-inbox-outbox-scenario.js +9 -30
  33. package/dist/cjs/performance/scripts/run-inbox-outbox-scenario.js.map +1 -0
  34. package/dist/cjs/performance/scripts/run-scenario.d.ts.map +1 -0
  35. package/dist/{performance → cjs/performance}/scripts/run-scenario.js +3 -3
  36. package/dist/cjs/performance/scripts/run-scenario.js.map +1 -0
  37. package/dist/cjs/performance/utils/colorize-text.d.ts.map +1 -0
  38. package/dist/cjs/performance/utils/colorize-text.js.map +1 -0
  39. package/dist/cjs/performance/utils/index.d.ts +3 -0
  40. package/dist/cjs/performance/utils/index.d.ts.map +1 -0
  41. package/dist/{performance → cjs/performance}/utils/index.js +2 -2
  42. package/dist/cjs/performance/utils/index.js.map +1 -0
  43. package/dist/{performance → cjs/performance}/utils/report-generation.d.ts +1 -1
  44. package/dist/cjs/performance/utils/report-generation.d.ts.map +1 -0
  45. package/dist/{performance → cjs/performance}/utils/report-generation.js +12 -15
  46. package/dist/cjs/performance/utils/report-generation.js.map +1 -0
  47. package/dist/esm/index.d.ts +2 -0
  48. package/dist/esm/index.d.ts.map +1 -0
  49. package/dist/esm/index.js +2 -0
  50. package/dist/esm/index.js.map +1 -0
  51. package/dist/esm/package.json +1 -0
  52. package/dist/esm/performance/index.d.ts +3 -0
  53. package/dist/esm/performance/index.d.ts.map +1 -0
  54. package/dist/esm/performance/index.js +3 -0
  55. package/dist/esm/performance/index.js.map +1 -0
  56. package/dist/esm/performance/plugins/inbox-outbox-report-endpoint-plugin.d.ts +22 -0
  57. package/dist/esm/performance/plugins/inbox-outbox-report-endpoint-plugin.d.ts.map +1 -0
  58. package/dist/esm/performance/plugins/inbox-outbox-report-endpoint-plugin.js +68 -0
  59. package/dist/esm/performance/plugins/inbox-outbox-report-endpoint-plugin.js.map +1 -0
  60. package/dist/esm/performance/plugins/inbox-outbox-state-endpoint-plugin.d.ts +23 -0
  61. package/dist/esm/performance/plugins/inbox-outbox-state-endpoint-plugin.d.ts.map +1 -0
  62. package/dist/esm/performance/plugins/inbox-outbox-state-endpoint-plugin.js +78 -0
  63. package/dist/esm/performance/plugins/inbox-outbox-state-endpoint-plugin.js.map +1 -0
  64. package/dist/esm/performance/plugins/index.d.ts +3 -0
  65. package/dist/esm/performance/plugins/index.d.ts.map +1 -0
  66. package/dist/{performance/plugins/index.d.ts → esm/performance/plugins/index.js} +3 -3
  67. package/dist/esm/performance/plugins/index.js.map +1 -0
  68. package/dist/esm/performance/scripts/index.d.ts +4 -0
  69. package/dist/esm/performance/scripts/index.d.ts.map +1 -0
  70. package/dist/esm/performance/scripts/index.js +4 -0
  71. package/dist/esm/performance/scripts/index.js.map +1 -0
  72. package/dist/esm/performance/scripts/make-graphql-request.d.ts +29 -0
  73. package/dist/esm/performance/scripts/make-graphql-request.d.ts.map +1 -0
  74. package/dist/esm/performance/scripts/make-graphql-request.js +16 -0
  75. package/dist/esm/performance/scripts/make-graphql-request.js.map +1 -0
  76. package/dist/esm/performance/scripts/run-inbox-outbox-scenario.d.ts +97 -0
  77. package/dist/esm/performance/scripts/run-inbox-outbox-scenario.d.ts.map +1 -0
  78. package/dist/esm/performance/scripts/run-inbox-outbox-scenario.js +141 -0
  79. package/dist/esm/performance/scripts/run-inbox-outbox-scenario.js.map +1 -0
  80. package/dist/esm/performance/scripts/run-scenario.d.ts +54 -0
  81. package/dist/esm/performance/scripts/run-scenario.d.ts.map +1 -0
  82. package/dist/esm/performance/scripts/run-scenario.js +33 -0
  83. package/dist/esm/performance/scripts/run-scenario.js.map +1 -0
  84. package/dist/esm/performance/utils/colorize-text.d.ts +3 -0
  85. package/dist/esm/performance/utils/colorize-text.d.ts.map +1 -0
  86. package/dist/esm/performance/utils/colorize-text.js +3 -0
  87. package/dist/esm/performance/utils/colorize-text.js.map +1 -0
  88. package/dist/esm/performance/utils/index.d.ts +3 -0
  89. package/dist/esm/performance/utils/index.d.ts.map +1 -0
  90. package/dist/esm/performance/utils/index.js +3 -0
  91. package/dist/esm/performance/utils/index.js.map +1 -0
  92. package/dist/esm/performance/utils/report-generation.d.ts +14 -0
  93. package/dist/esm/performance/utils/report-generation.d.ts.map +1 -0
  94. package/dist/esm/performance/utils/report-generation.js +235 -0
  95. package/dist/esm/performance/utils/report-generation.js.map +1 -0
  96. package/package.json +21 -11
  97. package/src/index.ts +1 -1
  98. package/src/performance/index.ts +2 -2
  99. package/src/performance/plugins/inbox-outbox-report-endpoint-plugin.spec.ts +6 -3
  100. package/src/performance/plugins/inbox-outbox-report-endpoint-plugin.ts +3 -3
  101. package/src/performance/plugins/inbox-outbox-state-endpoint-plugin.spec.ts +6 -3
  102. package/src/performance/plugins/inbox-outbox-state-endpoint-plugin.ts +2 -2
  103. package/src/performance/plugins/index.ts +2 -2
  104. package/src/performance/scripts/index.ts +3 -3
  105. package/src/performance/scripts/make-graphql-request.ts +4 -3
  106. package/src/performance/scripts/run-inbox-outbox-scenario.ts +8 -8
  107. package/src/performance/scripts/run-scenario.ts +1 -1
  108. package/src/performance/utils/index.ts +2 -2
  109. package/src/performance/utils/report-generation.ts +2 -2
  110. package/src/tests/utils/index.ts +1 -1
  111. package/src/tests/utils/stub-helpers.ts +2 -2
  112. package/dist/index.d.ts +0 -2
  113. package/dist/index.js.map +0 -1
  114. package/dist/performance/index.d.ts +0 -3
  115. package/dist/performance/index.d.ts.map +0 -1
  116. package/dist/performance/index.js.map +0 -1
  117. package/dist/performance/plugins/inbox-outbox-report-endpoint-plugin.d.ts.map +0 -1
  118. package/dist/performance/plugins/inbox-outbox-report-endpoint-plugin.js.map +0 -1
  119. package/dist/performance/plugins/inbox-outbox-state-endpoint-plugin.d.ts.map +0 -1
  120. package/dist/performance/plugins/inbox-outbox-state-endpoint-plugin.js.map +0 -1
  121. package/dist/performance/plugins/index.d.ts.map +0 -1
  122. package/dist/performance/plugins/index.js.map +0 -1
  123. package/dist/performance/scripts/index.d.ts +0 -4
  124. package/dist/performance/scripts/index.d.ts.map +0 -1
  125. package/dist/performance/scripts/index.js.map +0 -1
  126. package/dist/performance/scripts/make-graphql-request.d.ts.map +0 -1
  127. package/dist/performance/scripts/make-graphql-request.js.map +0 -1
  128. package/dist/performance/scripts/run-inbox-outbox-scenario.d.ts.map +0 -1
  129. package/dist/performance/scripts/run-inbox-outbox-scenario.js.map +0 -1
  130. package/dist/performance/scripts/run-scenario.d.ts.map +0 -1
  131. package/dist/performance/scripts/run-scenario.js.map +0 -1
  132. package/dist/performance/utils/colorize-text.d.ts.map +0 -1
  133. package/dist/performance/utils/colorize-text.js.map +0 -1
  134. package/dist/performance/utils/index.d.ts +0 -3
  135. package/dist/performance/utils/index.d.ts.map +0 -1
  136. package/dist/performance/utils/index.js.map +0 -1
  137. package/dist/performance/utils/report-generation.d.ts.map +0 -1
  138. package/dist/performance/utils/report-generation.js.map +0 -1
  139. /package/dist/{performance → cjs/performance}/scripts/run-scenario.d.ts +0 -0
  140. /package/dist/{performance → cjs/performance}/utils/colorize-text.d.ts +0 -0
  141. /package/dist/{performance → cjs/performance}/utils/colorize-text.js +0 -0
@@ -0,0 +1,68 @@
1
+ import { gql, makeExtendSchemaPlugin } from 'graphile-utils';
2
+ import { getGeneralReport, getProcessedReport, getReportRows, getStoredReport, } from '../utils/index.js';
3
+ const inboxReport = 'inboxReport';
4
+ const outboxReport = 'outboxReport';
5
+ const inboxOutboxReport = 'inboxOutboxReport';
6
+ const getReport = async (table, testId, ownerPool) => {
7
+ const entries = await getReportRows(table, testId, ownerPool);
8
+ if (entries.length === 0) {
9
+ return `No ${table} entries found.`;
10
+ }
11
+ const generalReport = getGeneralReport(entries, testId);
12
+ const storedReport = getStoredReport(entries, table);
13
+ const processedReport = getProcessedReport(entries, table);
14
+ return `${generalReport}\n\n${storedReport}\n\n${processedReport}`;
15
+ };
16
+ /**
17
+ * Returns a postgraphile plugin function that generates a performance report
18
+ * for inbox and/or outbox entries for a specific testId. Undefined will be
19
+ * returned for a report value that is not explicitly requested.
20
+ */
21
+ export const getInboxOutboxReportFunction = (ownerPool) => {
22
+ return async (_query, { input: { testId } }, _context, { fieldNodes }) => {
23
+ const selectedProperties = fieldNodes
24
+ .find((node) => node.name.value === inboxOutboxReport)
25
+ ?.selectionSet?.selections.map((s) => s.name.value) ??
26
+ [];
27
+ const inboxResult = selectedProperties.includes(inboxReport)
28
+ ? await getReport('inbox', testId, ownerPool)
29
+ : undefined;
30
+ const outboxResult = selectedProperties.includes(outboxReport)
31
+ ? await getReport('outbox', testId, ownerPool)
32
+ : undefined;
33
+ return {
34
+ [inboxReport]: inboxResult,
35
+ [outboxReport]: outboxResult,
36
+ };
37
+ };
38
+ };
39
+ /**
40
+ * Plugin that adds a custom graphql endpoint `inboxOutboxReport` which uses
41
+ * inbox and/or outbox entries with the specific test ID and generates a
42
+ * performance report for said entries. Test ID is expected to be passed as
43
+ * `message_context: { testId: "test ID value"}` with the message and is a
44
+ * expected to be string. `ownerPool` must be available as part of the
45
+ * postgraphile `graphileBuildOptions`.
46
+ */
47
+ export const InboxOutboxReportEndpointPlugin = makeExtendSchemaPlugin((_, { ownerPool }) => {
48
+ return {
49
+ typeDefs: gql `
50
+ input InboxOutboxReportInput {
51
+ testId: String!
52
+ }
53
+ type InboxOutboxReportPayload {
54
+ ${inboxReport}: String!
55
+ ${outboxReport}: String!
56
+ }
57
+ extend type Query {
58
+ ${inboxOutboxReport}(input: InboxOutboxReportInput!): InboxOutboxReportPayload
59
+ }
60
+ `,
61
+ resolvers: {
62
+ Query: {
63
+ [inboxOutboxReport]: getInboxOutboxReportFunction(ownerPool),
64
+ },
65
+ },
66
+ };
67
+ });
68
+ //# sourceMappingURL=inbox-outbox-report-endpoint-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inbox-outbox-report-endpoint-plugin.js","sourceRoot":"","sources":["../../../../src/performance/plugins/inbox-outbox-report-endpoint-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAG7D,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,WAAW,GAAG,aAAa,CAAC;AAClC,MAAM,YAAY,GAAG,cAAc,CAAC;AACpC,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AAE9C,MAAM,SAAS,GAAG,KAAK,EACrB,KAAyB,EACzB,MAAc,EACd,SAAe,EACE,EAAE;IACnB,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IAC9D,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,MAAM,KAAK,iBAAiB,CAAC;IACtC,CAAC;IACD,MAAM,aAAa,GAAG,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACxD,MAAM,YAAY,GAAG,eAAe,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACrD,MAAM,eAAe,GAAG,kBAAkB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC3D,OAAO,GAAG,aAAa,OAAO,YAAY,OAAO,eAAe,EAAE,CAAC;AACrE,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,SAAe,EAAE,EAAE;IAC9D,OAAO,KAAK,EACV,MAAe,EACf,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAiC,EACpD,QAAiB,EACjB,EAAE,UAAU,EAAsB,EACA,EAAE;QACpC,MAAM,kBAAkB,GACtB,UAAU;aACP,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,iBAAiB,CAAC;YACtD,EAAE,YAAY,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAE,CAAe,CAAC,IAAI,CAAC,KAAK,CAAC;YACpE,EAAE,CAAC;QAEL,MAAM,WAAW,GAAG,kBAAkB,CAAC,QAAQ,CAAC,WAAW,CAAC;YAC1D,CAAC,CAAC,MAAM,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC;YAC7C,CAAC,CAAC,SAAS,CAAC;QACd,MAAM,YAAY,GAAG,kBAAkB,CAAC,QAAQ,CAAC,YAAY,CAAC;YAC5D,CAAC,CAAC,MAAM,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC;YAC9C,CAAC,CAAC,SAAS,CAAC;QAEd,OAAO;YACL,CAAC,WAAW,CAAC,EAAE,WAAW;YAC1B,CAAC,YAAY,CAAC,EAAE,YAAY;SAC7B,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,sBAAsB,CACnE,CAAC,CAAC,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE;IACnB,OAAO;QACL,QAAQ,EAAE,GAAG,CAAA;;;;;UAKT,WAAW;UACX,YAAY;;;UAGZ,iBAAiB;;KAEtB;QACC,SAAS,EAAE;YACT,KAAK,EAAE;gBACL,CAAC,iBAAiB,CAAC,EAAE,4BAA4B,CAAC,SAAS,CAAC;aAC7D;SACF;KACF,CAAC;AACJ,CAAC,CACF,CAAC"}
@@ -0,0 +1,23 @@
1
+ import type { GraphQLResolveInfo } from 'graphql';
2
+ import type { Pool } from 'pg';
3
+ /**
4
+ * Returns a postgraphile plugin function that returns the counts of inbox
5
+ * and/or outbox entries that are still not completed and not abandoned for a
6
+ * specified testId. Undefined will be returned for a count value that is not
7
+ * explicitly requested.
8
+ */
9
+ export declare const getInboxOutboxStateFunction: (ownerPool: Pool) => (_query: unknown, { input: { testId } }: {
10
+ input: {
11
+ testId: string;
12
+ };
13
+ }, _context: unknown, { fieldNodes }: GraphQLResolveInfo) => Promise<Record<string, unknown>>;
14
+ /**
15
+ * Plugin that adds a custom graphql endpoint `inboxOutboxState` which checks if
16
+ * inbox and/or outbox entries with the specific test ID are still being
17
+ * processed and returns the count of such entries. Test ID is expected to be
18
+ * passed as `message_context: { testId: "test ID value"}` with the message and
19
+ * is a expected to be string. `ownerPool` must be available as part of the
20
+ * postgraphile `graphileBuildOptions`.
21
+ */
22
+ export declare const InboxOutboxStateEndpointPlugin: import("graphile-build").Plugin;
23
+ //# sourceMappingURL=inbox-outbox-state-endpoint-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inbox-outbox-state-endpoint-plugin.d.ts","sourceRoot":"","sources":["../../../../src/performance/plugins/inbox-outbox-state-endpoint-plugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAa,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAmC/B;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,GAAI,WAAW,IAAI,MAEvD,QAAQ,OAAO,EACf,uBAAuB;IAAE,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,EACpD,UAAU,OAAO,EACjB,gBAAgB,kBAAkB,KACjC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAmBnC,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,8BAA8B,iCAsB1C,CAAC"}
@@ -0,0 +1,78 @@
1
+ import { gql, makeExtendSchemaPlugin } from 'graphile-utils';
2
+ const inboxActiveCount = 'inboxActiveCount';
3
+ const outboxActiveCount = 'outboxActiveCount';
4
+ const inboxOutboxState = 'inboxOutboxState';
5
+ /**
6
+ * Queries for the count of rows of either inbox or outbox table for not
7
+ * processed and not abandoned rows for a specified testId.
8
+ */
9
+ const getRowsCount = async (table, testId, ownerPool) => {
10
+ const client = await ownerPool.connect();
11
+ try {
12
+ const testIdPath = table === 'inbox'
13
+ ? `metadata->'messageContext'->>'testId'`
14
+ : `metadata->'envelopeOverrides'->'message_context'->>'testId'`;
15
+ const result = await client.query(`SELECT COUNT(id) FROM app_hidden.${table}
16
+ WHERE ${testIdPath} = $1 AND
17
+ processed_at is NULL AND
18
+ abandoned_at is NULL;`, [testId]);
19
+ return result.rows[0].count;
20
+ }
21
+ finally {
22
+ client.release();
23
+ }
24
+ };
25
+ /**
26
+ * Returns a postgraphile plugin function that returns the counts of inbox
27
+ * and/or outbox entries that are still not completed and not abandoned for a
28
+ * specified testId. Undefined will be returned for a count value that is not
29
+ * explicitly requested.
30
+ */
31
+ export const getInboxOutboxStateFunction = (ownerPool) => {
32
+ return async (_query, { input: { testId } }, _context, { fieldNodes }) => {
33
+ const selectedProperties = fieldNodes
34
+ .find((node) => node.name.value === inboxOutboxState)
35
+ ?.selectionSet?.selections.map((s) => s.name.value) ??
36
+ [];
37
+ const inboxResult = selectedProperties.includes(inboxActiveCount)
38
+ ? await getRowsCount('inbox', testId, ownerPool)
39
+ : undefined;
40
+ const outboxResult = selectedProperties.includes(outboxActiveCount)
41
+ ? await getRowsCount('outbox', testId, ownerPool)
42
+ : undefined;
43
+ return {
44
+ [inboxActiveCount]: inboxResult,
45
+ [outboxActiveCount]: outboxResult,
46
+ };
47
+ };
48
+ };
49
+ /**
50
+ * Plugin that adds a custom graphql endpoint `inboxOutboxState` which checks if
51
+ * inbox and/or outbox entries with the specific test ID are still being
52
+ * processed and returns the count of such entries. Test ID is expected to be
53
+ * passed as `message_context: { testId: "test ID value"}` with the message and
54
+ * is a expected to be string. `ownerPool` must be available as part of the
55
+ * postgraphile `graphileBuildOptions`.
56
+ */
57
+ export const InboxOutboxStateEndpointPlugin = makeExtendSchemaPlugin((_, { ownerPool }) => {
58
+ return {
59
+ typeDefs: gql `
60
+ input InboxOutboxStateInput {
61
+ testId: String!
62
+ }
63
+ type InboxOutboxStatePayload {
64
+ ${inboxActiveCount}: Int!
65
+ ${outboxActiveCount}: Int!
66
+ }
67
+ extend type Query {
68
+ ${inboxOutboxState}(input: InboxOutboxStateInput!): InboxOutboxStatePayload
69
+ }
70
+ `,
71
+ resolvers: {
72
+ Query: {
73
+ [inboxOutboxState]: getInboxOutboxStateFunction(ownerPool),
74
+ },
75
+ },
76
+ };
77
+ });
78
+ //# sourceMappingURL=inbox-outbox-state-endpoint-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inbox-outbox-state-endpoint-plugin.js","sourceRoot":"","sources":["../../../../src/performance/plugins/inbox-outbox-state-endpoint-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAI7D,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AAC5C,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AAC9C,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AAE5C;;;GAGG;AACH,MAAM,YAAY,GAAG,KAAK,EACxB,KAAyB,EACzB,MAAc,EACd,SAAe,EACE,EAAE;IACnB,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,OAAO,EAAE,CAAC;IACzC,IAAI,CAAC;QACH,MAAM,UAAU,GACd,KAAK,KAAK,OAAO;YACf,CAAC,CAAC,uCAAuC;YACzC,CAAC,CAAC,6DAA6D,CAAC;QACpE,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,KAAK,CAC/B,oCAAoC,KAAK;cACjC,UAAU;;4BAEI,EACtB,CAAC,MAAM,CAAC,CACT,CAAC;QAEF,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC9B,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,OAAO,EAAE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;gBACL,CAAC,gBAAgB,CAAC,EAAE,2BAA2B,CAAC,SAAS,CAAC;aAC3D;SACF;KACF,CAAC;AACJ,CAAC,CACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { InboxOutboxReportEndpointPlugin } from './inbox-outbox-report-endpoint-plugin.js';
2
+ export { InboxOutboxStateEndpointPlugin } from './inbox-outbox-state-endpoint-plugin.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/performance/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,0CAA0C,CAAC;AAC3F,OAAO,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAC"}
@@ -1,3 +1,3 @@
1
- export { InboxOutboxReportEndpointPlugin } from './inbox-outbox-report-endpoint-plugin';
2
- export { InboxOutboxStateEndpointPlugin } from './inbox-outbox-state-endpoint-plugin';
3
- //# sourceMappingURL=index.d.ts.map
1
+ export { InboxOutboxReportEndpointPlugin } from './inbox-outbox-report-endpoint-plugin.js';
2
+ export { InboxOutboxStateEndpointPlugin } from './inbox-outbox-state-endpoint-plugin.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/performance/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,0CAA0C,CAAC;AAC3F,OAAO,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './make-graphql-request.js';
2
+ export * from './run-inbox-outbox-scenario.js';
3
+ export * from './run-scenario.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/performance/scripts/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './make-graphql-request.js';
2
+ export * from './run-inbox-outbox-scenario.js';
3
+ export * from './run-scenario.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/performance/scripts/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,29 @@
1
+ import type { AxiosResponse } from 'axios';
2
+ import type { DocumentNode } from 'graphql';
3
+ /**
4
+ * Config to make a GraphQL request using `makeGraphQLRequest`
5
+ */
6
+ export interface MakeGraphQLRequestOptions {
7
+ /**
8
+ * Base URL that should be requested. `/graphql` will be attached to it to
9
+ * make a request.
10
+ */
11
+ baseUrl: string;
12
+ /**
13
+ * Operation to request. Use `graphql-tag` to wrap the operation string.
14
+ */
15
+ operation: DocumentNode;
16
+ /**
17
+ * Optional GraphQL request variables.
18
+ */
19
+ variables?: Record<string, unknown>;
20
+ /**
21
+ * Bearer authorization token.
22
+ */
23
+ token: string;
24
+ }
25
+ /**
26
+ * Wrapper to make a GraphQL request with minimal input parameters
27
+ */
28
+ export declare const makeGraphQLRequest: ({ baseUrl, operation, variables, token, }: MakeGraphQLRequestOptions) => Promise<AxiosResponse<any, any>>;
29
+ //# sourceMappingURL=make-graphql-request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"make-graphql-request.d.ts","sourceRoot":"","sources":["../../../../src/performance/scripts/make-graphql-request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG5C;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,SAAS,EAAE,YAAY,CAAC;IACxB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAAU,2CAMzC,yBAAyB,KAAG,OAAO,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,CAa1D,CAAC"}
@@ -0,0 +1,16 @@
1
+ import axios from 'axios';
2
+ import { print } from 'graphql/language/printer.js';
3
+ /**
4
+ * Wrapper to make a GraphQL request with minimal input parameters
5
+ */
6
+ export const makeGraphQLRequest = async ({ baseUrl, operation, variables, token, }) => {
7
+ return axios.post(new URL('graphql', baseUrl).href, {
8
+ query: print(operation),
9
+ variables,
10
+ }, {
11
+ headers: {
12
+ Authorization: `Bearer ${token}`,
13
+ },
14
+ });
15
+ };
16
+ //# sourceMappingURL=make-graphql-request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"make-graphql-request.js","sourceRoot":"","sources":["../../../../src/performance/scripts/make-graphql-request.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAyBpD;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EAAE,EACvC,OAAO,EACP,SAAS,EACT,SAAS,EACT,KAAK,GAEkB,EAAoC,EAAE;IAC7D,OAAO,KAAK,CAAC,IAAI,CACf,IAAI,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,IAAI,EAChC;QACE,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;QACvB,SAAS;KACV,EACD;QACE,OAAO,EAAE;YACP,aAAa,EAAE,UAAU,KAAK,EAAE;SACjC;KACF,CACF,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,97 @@
1
+ import { Broker } from '@axinom/mosaic-message-bus';
2
+ import { type MessagingSettings } from '@axinom/mosaic-message-bus-abstractions';
3
+ import { type BasicConfig, type BasicCustomizableConfig, type BasicManagedServiceConfig, type BasicRMQConfig, type ShutdownAction } from '@axinom/mosaic-service-common';
4
+ import { type RunnerConfig } from './run-scenario.js';
5
+ /**
6
+ * Configuration with all messaging-related environment variable values,
7
+ */
8
+ type InboxOutboxMessagingConfig = Pick<BasicConfig & BasicRMQConfig & BasicManagedServiceConfig & BasicCustomizableConfig, 'serviceId' | 'tenantId' | 'environmentId' | 'idServiceAuthBaseUrl' | 'managedServiceAccountClientId' | 'managedServiceAccountClientSecret' | 'isDev' | 'rmqHost' | 'rmqPort' | 'rmqProtocol' | 'rmqUser' | 'rmqVHost' | 'rmqPassword' | 'rmqVHostAssert'>;
9
+ /**
10
+ * Configuration to run `runInboxOutboxScenario` function.
11
+ */
12
+ interface InboxOutboxRunScenarioConfig {
13
+ /**
14
+ * Description of the scenario. Printed together with the report.
15
+ */
16
+ description?: string;
17
+ /**
18
+ * Configuration to fine-tune how scenario is executed.
19
+ */
20
+ runnerConfig?: RunnerConfig;
21
+ /**
22
+ * Messaging settings for the message that will be repeatedly sent.
23
+ */
24
+ messagingSettings: MessagingSettings;
25
+ /**
26
+ * Configuration to be able to send messages, e.g. RabbitMQ connection details.
27
+ */
28
+ config: InboxOutboxMessagingConfig;
29
+ /**
30
+ * Payload to be sent with each iteration.
31
+ */
32
+ payload: unknown | (() => unknown);
33
+ /**
34
+ * Base URL for the service. Used to request `inboxOutboxState` and
35
+ * `inboxOutboxReport` operations.
36
+ */
37
+ serviceBaseUrl: string;
38
+ }
39
+ /**
40
+ * Config that is created by the `setup` step of `getInboxOutboxSetup` and
41
+ * passed to each function/step of `runInboxOutboxScenario`
42
+ */
43
+ export interface InboxOutboxScenarioConfig {
44
+ /**
45
+ * Configuration to be able to send messages, e.g. RabbitMQ connection details.
46
+ */
47
+ config: InboxOutboxMessagingConfig;
48
+ /**
49
+ * Shutdown actions that are executed as part of the `teardown` step.
50
+ */
51
+ shutdownActions: ShutdownAction[];
52
+ /**
53
+ * Messaging broker to send RabbitMQ messages.
54
+ */
55
+ broker: Broker;
56
+ /**
57
+ * Authorization token to include in messages and GraphQL requests.
58
+ */
59
+ token: string;
60
+ /**
61
+ * Test identifier. Passed along with each sent message as part of
62
+ * `message_context` and used to retrieve the inbox/outbox state and report.
63
+ */
64
+ testId: string;
65
+ }
66
+ /**
67
+ * Generic setup function to produce all required components to run messaging
68
+ * tests for services using transactional inbox-outbox pattern.
69
+ */
70
+ export declare const getInboxOutboxSetup: <T extends InboxOutboxScenarioConfig>(messagingSettings: MessagingSettings, config: InboxOutboxMessagingConfig) => (() => Promise<T>);
71
+ /**
72
+ * Generic iteration function to send RabbitMQ messages.
73
+ */
74
+ export declare const getInboxOutboxIteration: <T extends InboxOutboxScenarioConfig>(payload: unknown, messagingSettings: MessagingSettings) => ({ broker, token, testId, config }: T) => Promise<void>;
75
+ /**
76
+ * Generic hasScenarioCompleted function to check if all inbox and outbox
77
+ * messages have been processed.
78
+ */
79
+ export declare const getInboxOutboxHasScenarioCompleted: <T extends InboxOutboxScenarioConfig>(serviceBaseUrl: string) => ((tc: T) => Promise<boolean>);
80
+ /**
81
+ * Generic function to request a report from the target service that scenario is
82
+ * running against.
83
+ */
84
+ export declare const getInboxOutboxGenerateReport: <T extends InboxOutboxScenarioConfig>(serviceBaseUrl: string) => ({ token, testId }: T) => Promise<string>;
85
+ /**
86
+ * Generic function to run all shutdown actions, e.g. dispose the broker.
87
+ */
88
+ export declare const inboxOutboxTeardown: <T extends InboxOutboxScenarioConfig>({ shutdownActions, }: T) => Promise<void>;
89
+ /**
90
+ * A wrapper function for the `runScenario` to send RabbitMQ messages for the
91
+ * service using transactional inbox-outbox pattern. Has limited configuration
92
+ * fitting for simple cases where sending a message with the same payload is
93
+ * acceptable. For more complex scenarios - consider using `runScenario` explicitly.
94
+ */
95
+ export declare const runInboxOutboxScenario: <T extends InboxOutboxScenarioConfig>({ runnerConfig, messagingSettings, config, payload, serviceBaseUrl, description, }: InboxOutboxRunScenarioConfig) => Promise<void>;
96
+ export {};
97
+ //# sourceMappingURL=run-inbox-outbox-scenario.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-inbox-outbox-scenario.d.ts","sourceRoot":"","sources":["../../../../src/performance/scripts/run-inbox-outbox-scenario.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,MAAM,EAGP,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AACjF,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,uBAAuB,EAC5B,KAAK,yBAAyB,EAC9B,KAAK,cAAc,EAEnB,KAAK,cAAc,EAEpB,MAAM,+BAA+B,CAAC;AAIvC,OAAO,EAAE,KAAK,YAAY,EAAe,MAAM,mBAAmB,CAAC;AAEnE;;GAEG;AACH,KAAK,0BAA0B,GAAG,IAAI,CACpC,WAAW,GACT,cAAc,GACd,yBAAyB,GACzB,uBAAuB,EACvB,WAAW,GACX,UAAU,GACV,eAAe,GACf,sBAAsB,GACtB,+BAA+B,GAC/B,mCAAmC,GACnC,OAAO,GACP,SAAS,GACT,SAAS,GACT,aAAa,GACb,SAAS,GACT,UAAU,GACV,aAAa,GACb,gBAAgB,CACnB,CAAC;AAEF;;GAEG;AACH,UAAU,4BAA4B;IACpC;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B;;OAEG;IACH,iBAAiB,EAAE,iBAAiB,CAAC;IACrC;;OAEG;IACH,MAAM,EAAE,0BAA0B,CAAC;IACnC;;OAEG;IACH,OAAO,EAAE,OAAO,GAAG,CAAC,MAAM,OAAO,CAAC,CAAC;IACnC;;;OAGG;IACH,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,MAAM,EAAE,0BAA0B,CAAC;IACnC;;OAEG;IACH,eAAe,EAAE,cAAc,EAAE,CAAC;IAClC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,yBAAyB,EACrE,mBAAmB,iBAAiB,EACpC,QAAQ,0BAA0B,KACjC,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAkCnB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,uBAAuB,GAAI,CAAC,SAAS,yBAAyB,EACzE,SAAS,OAAO,EAChB,mBAAmB,iBAAiB,MAEtB,mCAAmC,CAAC,KAAG,OAAO,CAAC,IAAI,CAMlE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,kCAAkC,GAC7C,CAAC,SAAS,yBAAyB,EAEnC,gBAAgB,MAAM,KACrB,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAsC9B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,4BAA4B,GACvC,CAAC,SAAS,yBAAyB,EAEnC,gBAAgB,MAAM,MAER,mBAAmB,CAAC,KAAG,OAAO,CAAC,MAAM,CAgBpD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAAU,CAAC,SAAS,yBAAyB,EAAE,sBAE5E,CAAC,KAAG,OAAO,CAAC,IAAI,CAIlB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,GACjC,CAAC,SAAS,yBAAyB,EACnC,oFAOC,4BAA4B,KAAG,OAAO,CAAC,IAAI,CAc7C,CAAC"}
@@ -0,0 +1,141 @@
1
+ /* eslint-disable no-console */
2
+ import { getManagedServiceAccountToken } from '@axinom/mosaic-id-link-be';
3
+ import { Broker, RascalConfigBuilder, setupMessagingBroker, } from '@axinom/mosaic-message-bus';
4
+ import {} from '@axinom/mosaic-message-bus-abstractions';
5
+ import { Logger, ShutdownActionsMiddleware, } from '@axinom/mosaic-service-common';
6
+ import gql from 'graphql-tag';
7
+ import { randomUUID } from 'node:crypto';
8
+ import { makeGraphQLRequest } from './make-graphql-request.js';
9
+ import { runScenario } from './run-scenario.js';
10
+ /**
11
+ * Generic setup function to produce all required components to run messaging
12
+ * tests for services using transactional inbox-outbox pattern.
13
+ */
14
+ export const getInboxOutboxSetup = (messagingSettings, config) => {
15
+ return async () => {
16
+ const shutdownActions = [];
17
+ const builder = new RascalConfigBuilder(messagingSettings, config);
18
+ const broker = await setupMessagingBroker({
19
+ config,
20
+ builders: [
21
+ messagingSettings.action === 'command'
22
+ ? builder.sendCommand()
23
+ : builder.publishEvent(),
24
+ ],
25
+ logger: new Logger({ config }),
26
+ // we just want setupMessagingBroker to push shutdown actions to an array
27
+ // and call it manually
28
+ shutdownActions: shutdownActions,
29
+ });
30
+ const token = (await getManagedServiceAccountToken(config.idServiceAuthBaseUrl, config.managedServiceAccountClientId, config.managedServiceAccountClientSecret, config.tenantId, config.environmentId)).accessToken;
31
+ return {
32
+ testId: randomUUID(),
33
+ config,
34
+ broker,
35
+ token,
36
+ shutdownActions,
37
+ };
38
+ };
39
+ };
40
+ /**
41
+ * Generic iteration function to send RabbitMQ messages.
42
+ */
43
+ export const getInboxOutboxIteration = (payload, messagingSettings) => {
44
+ return async ({ broker, token, testId, config }) => {
45
+ await broker.publish(config.environmentId, messagingSettings, payload, {
46
+ auth_token: token,
47
+ message_context: { testId },
48
+ });
49
+ };
50
+ };
51
+ /**
52
+ * Generic hasScenarioCompleted function to check if all inbox and outbox
53
+ * messages have been processed.
54
+ */
55
+ export const getInboxOutboxHasScenarioCompleted = (serviceBaseUrl) => {
56
+ let checks = 1;
57
+ let isFirstLog = true;
58
+ return async ({ token, testId }) => {
59
+ const response = await makeGraphQLRequest({
60
+ baseUrl: serviceBaseUrl,
61
+ token,
62
+ variables: { testId },
63
+ operation: gql `
64
+ query GetState($testId: String!) {
65
+ inboxOutboxState(input: { testId: $testId }) {
66
+ inboxActiveCount
67
+ outboxActiveCount
68
+ }
69
+ }
70
+ `,
71
+ });
72
+ const inbox = response.data.data.inboxOutboxState.inboxActiveCount;
73
+ const outbox = response.data.data.inboxOutboxState.outboxActiveCount;
74
+ const clearLine = ' '.repeat(10); // Empty line to clear leftover characters
75
+ process.stdout.write(`${isFirstLog ? '' : '\r' // erase previous log in the terminal to preserve space for multiple reports
76
+ }Waiting for all messages to be processed: inbox - ${inbox}; outbox - ${outbox}${clearLine}`);
77
+ if (isFirstLog) {
78
+ isFirstLog = false;
79
+ }
80
+ if (inbox === 0 && outbox === 0 && checks > 1) {
81
+ process.stdout.write('\n'); // make sure next log is not written on the same line as the log above
82
+ return true;
83
+ }
84
+ else if (inbox === 0 && outbox === 0) {
85
+ // Make sure it does not bounce back, so doing 2 checks
86
+ checks++;
87
+ }
88
+ return false;
89
+ };
90
+ };
91
+ /**
92
+ * Generic function to request a report from the target service that scenario is
93
+ * running against.
94
+ */
95
+ export const getInboxOutboxGenerateReport = (serviceBaseUrl) => {
96
+ return async ({ token, testId }) => {
97
+ const response = await makeGraphQLRequest({
98
+ baseUrl: serviceBaseUrl,
99
+ token,
100
+ variables: { testId },
101
+ operation: gql `
102
+ query GetInboxOutboxReport($testId: String!) {
103
+ inboxOutboxReport(input: { testId: $testId }) {
104
+ inboxReport
105
+ outboxReport
106
+ }
107
+ }
108
+ `,
109
+ });
110
+ return `[INBOX]\n${response.data.data.inboxOutboxReport.inboxReport}\n\n[OUTBOX]\n${response.data.data.inboxOutboxReport.outboxReport}`;
111
+ };
112
+ };
113
+ /**
114
+ * Generic function to run all shutdown actions, e.g. dispose the broker.
115
+ */
116
+ export const inboxOutboxTeardown = async ({ shutdownActions, }) => {
117
+ for await (const shutdown of shutdownActions) {
118
+ await shutdown();
119
+ }
120
+ };
121
+ /**
122
+ * A wrapper function for the `runScenario` to send RabbitMQ messages for the
123
+ * service using transactional inbox-outbox pattern. Has limited configuration
124
+ * fitting for simple cases where sending a message with the same payload is
125
+ * acceptable. For more complex scenarios - consider using `runScenario` explicitly.
126
+ */
127
+ export const runInboxOutboxScenario = async ({ runnerConfig, messagingSettings, config, payload, serviceBaseUrl, description, }) => {
128
+ await runScenario({
129
+ description,
130
+ runnerConfig: {
131
+ iterations: runnerConfig?.iterations ?? 50,
132
+ awaitCompletionIntervalInSec: runnerConfig?.awaitCompletionIntervalInSec ?? 5,
133
+ },
134
+ setup: getInboxOutboxSetup(messagingSettings, config),
135
+ iteration: getInboxOutboxIteration(payload, messagingSettings),
136
+ hasScenarioCompleted: getInboxOutboxHasScenarioCompleted(serviceBaseUrl),
137
+ generateReport: getInboxOutboxGenerateReport(serviceBaseUrl),
138
+ teardown: inboxOutboxTeardown,
139
+ });
140
+ };
141
+ //# sourceMappingURL=run-inbox-outbox-scenario.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-inbox-outbox-scenario.js","sourceRoot":"","sources":["../../../../src/performance/scripts/run-inbox-outbox-scenario.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EACL,MAAM,EACN,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAA0B,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAKL,MAAM,EAEN,yBAAyB,GAC1B,MAAM,+BAA+B,CAAC;AACvC,OAAO,GAAG,MAAM,aAAa,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAqB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAqFnE;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,iBAAoC,EACpC,MAAkC,EACd,EAAE;IACtB,OAAO,KAAK,IAAgB,E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AAc,CAAC;QAC5D,QAAQ,EAAE,mBAAmB;KAC9B,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Configuration to fine-tune how scenario is executed.
3
+ */
4
+ export interface RunnerConfig {
5
+ /**
6
+ * Defines how many times the `iteration` function will be executed.
7
+ */
8
+ iterations: number;
9
+ /**
10
+ * Defines how long will the scenario wait to call the `hasScenarioCompleted`
11
+ * function to check if scenario is ready for report generation.
12
+ */
13
+ awaitCompletionIntervalInSec: number;
14
+ }
15
+ /**
16
+ * Configuration for the `runScenario` function.
17
+ */
18
+ export interface RunScenarioConfig<TC> {
19
+ /**
20
+ * Description of the scenario. Printed together with the report.
21
+ */
22
+ description?: string;
23
+ /**
24
+ * Configuration to fine-tune how scenario is executed.
25
+ */
26
+ runnerConfig: RunnerConfig;
27
+ /**
28
+ * Function to set up initial data that can be reused by other scenario functions.
29
+ */
30
+ setup: () => Promise<TC>;
31
+ /**
32
+ * Function that will be repeatedly executed as many times as defined in `runnerConfig.iterations`.
33
+ */
34
+ iteration: (tc: TC) => Promise<void>;
35
+ /**
36
+ * Function to check if scenario is completed, e.g. call a service API and
37
+ * return true or false based on response.
38
+ */
39
+ hasScenarioCompleted: (tc: TC) => Promise<boolean>;
40
+ /**
41
+ * Function to generate a report for the scenario. Printed as is.
42
+ */
43
+ generateReport: (tc: TC) => Promise<string>;
44
+ /**
45
+ * Function to cleanup after scenario is completed.
46
+ */
47
+ teardown: (tc: TC) => Promise<void>;
48
+ }
49
+ /**
50
+ * Generic function to execute a custom piece of code multiple times, await for
51
+ * the completion of processing caused by previous execution, and print a report.
52
+ */
53
+ export declare const runScenario: <TC>({ description, runnerConfig: { iterations, awaitCompletionIntervalInSec }, setup, iteration, hasScenarioCompleted, generateReport, teardown, }: RunScenarioConfig<TC>) => Promise<void>;
54
+ //# sourceMappingURL=run-scenario.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-scenario.d.ts","sourceRoot":"","sources":["../../../../src/performance/scripts/run-scenario.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,4BAA4B,EAAE,MAAM,CAAC;CACtC;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB,CAAC,EAAE;IACnC;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,YAAY,EAAE,YAAY,CAAC;IAC3B;;OAEG;IACH,KAAK,EAAE,MAAM,OAAO,CAAC,EAAE,CAAC,CAAC;IACzB;;OAEG;IACH,SAAS,EAAE,CAAC,EAAE,EAAE,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC;;;OAGG;IACH,oBAAoB,EAAE,CAAC,EAAE,EAAE,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACnD;;OAEG;IACH,cAAc,EAAE,CAAC,EAAE,EAAE,EAAE,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5C;;OAEG;IACH,QAAQ,EAAE,CAAC,EAAE,EAAE,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACrC;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAU,EAAE,EAAE,gJAQnC,iBAAiB,CAAC,EAAE,CAAC,KAAG,OAAO,CAAC,IAAI,CA6BtC,CAAC"}
@@ -0,0 +1,33 @@
1
+ /* eslint-disable no-console */
2
+ import { sleep } from '@axinom/mosaic-service-common';
3
+ import { blue } from '../utils/index.js';
4
+ /**
5
+ * Generic function to execute a custom piece of code multiple times, await for
6
+ * the completion of processing caused by previous execution, and print a report.
7
+ */
8
+ export const runScenario = async ({ description, runnerConfig: { iterations, awaitCompletionIntervalInSec }, setup, iteration, hasScenarioCompleted, generateReport, teardown, }) => {
9
+ console.log(blue(`Scenario has started:\n\t${description}`));
10
+ console.log('Performing setup...');
11
+ const tc = await setup();
12
+ console.log('Running iterations...');
13
+ Array.from({ length: iterations }).map(async () => {
14
+ await iteration(tc);
15
+ });
16
+ console.log('Checking if scenario is completed...');
17
+ while (!(await hasScenarioCompleted(tc))) {
18
+ await sleep(awaitCompletionIntervalInSec * 1000);
19
+ }
20
+ console.log(`Generating report...`);
21
+ const report = await generateReport(tc);
22
+ console.log('Performing teardown...');
23
+ await teardown(tc);
24
+ console.log(`Scenario has finished! See report below:`);
25
+ console.log('\n--------------------------------------------');
26
+ if (description) {
27
+ console.log(`- Scenario Description: ${blue(description)}\n`);
28
+ }
29
+ console.log(report);
30
+ console.log('--------------------------------------------\n');
31
+ process.exit(0);
32
+ };
33
+ //# sourceMappingURL=run-scenario.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-scenario.js","sourceRoot":"","sources":["../../../../src/performance/scripts/run-scenario.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAoDzC;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAAM,EACpC,WAAW,EACX,YAAY,EAAE,EAAE,UAAU,EAAE,4BAA4B,EAAE,EAC1D,KAAK,EACL,SAAS,EACT,oBAAoB,EACpB,cAAc,EACd,QAAQ,GACc,EAAiB,EAAE;IACzC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,4BAA4B,WAAW,EAAE,CAAC,CAAC,CAAC;IAC7D,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;IACnC,MAAM,EAAE,GAAG,MAAM,KAAK,EAAE,CAAC;IAEzB,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;IACrC,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE;QAChD,MAAM,SAAS,CAAC,EAAE,CAAC,CAAC;IACtB,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAC;IACpD,OAAO,CAAC,CAAC,MAAM,oBAAoB,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;QACzC,MAAM,KAAK,CAAC,4BAA4B,GAAG,IAAI,CAAC,CAAC;IACnD,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;IACpC,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;IAExC,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;IACtC,MAAM,QAAQ,CAAC,EAAE,CAAC,CAAC;IAEnB,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAC;IACxD,OAAO,CAAC,GAAG,CAAC,gDAAgD,CAAC,CAAC;IAC9D,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,CAAC,GAAG,CAAC,2BAA2B,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACpB,OAAO,CAAC,GAAG,CAAC,gDAAgD,CAAC,CAAC;IAC9D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare const blue: (text: string | number) => string;
2
+ export declare const red: (text: string | number) => string;
3
+ //# sourceMappingURL=colorize-text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colorize-text.d.ts","sourceRoot":"","sources":["../../../../src/performance/utils/colorize-text.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,GAAI,MAAM,MAAM,GAAG,MAAM,KAAG,MACd,CAAC;AAChC,eAAO,MAAM,GAAG,GAAI,MAAM,MAAM,GAAG,MAAM,KAAG,MACb,CAAC"}