Skip to content

Commit 4cbdacb

Browse files
committed
test: case to ensure counts aggregate up the tree correctly
1 parent 9f159dd commit 4cbdacb

1 file changed

Lines changed: 179 additions & 0 deletions

File tree

log-viewer/modules/__tests__/ApexLogParser.test.ts

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,3 +1180,182 @@ describe('Line Type Tests', () => {
11801180
expect(qp.sObjectType).toBe(null);
11811181
});
11821182
});
1183+
1184+
describe('Aggregating Totals', () => {
1185+
it('should sum from child to parent', () => {
1186+
const logArray = [
1187+
'01:02:03.04 (0)|EXECUTION_STARTED',
1188+
'01:02:03.04 (1)|METHOD_ENTRY|[1]|a00000000000000|ns.MyClass.myMethod()',
1189+
'01:02:03.04 (2)|METHOD_ENTRY|[1]|a00000000000000|ns.MyClass.soql()',
1190+
'01:02:03.04 (3)|SOQL_EXECUTE_BEGIN|[2]|Aggregations:0|SELECT ID FROM MyObject__c',
1191+
'01:02:03.04 (4)|SOQL_EXECUTE_END|[2]|Rows:1',
1192+
'01:02:03.04 (5)|SOQL_EXECUTE_BEGIN|[2]|Aggregations:0|SELECT ID FROM MyObject__c',
1193+
'01:02:03.04 (6)|SOQL_EXECUTE_END|[2]|Rows:2',
1194+
'01:02:03.04 (7)|METHOD_EXIT|[1]|a00000000000000|ns.MyClass.soql()',
1195+
'01:02:03.04 (8)|METHOD_ENTRY|[1]|a00000000000000|ns.MyClass.dml()',
1196+
'01:02:03.04 (9)|DML_BEGIN|[194]|Op:Update|Type:ns2__MyObject__c|Rows:1',
1197+
'01:02:03.04 (10)|DML_END|[194]',
1198+
'01:02:03.04 (11)|DML_BEGIN|[194]|Op:Update|Type:ns2__MyObject__c|Rows:4',
1199+
'01:02:03.04 (12)|DML_END|[194]',
1200+
'01:02:03.04 (13)|METHOD_EXIT|[1]|a00000000000000|ns.MyClass.dml()',
1201+
'01:02:03.04 (14)|METHOD_ENTRY|[1]|a00000000000000|ns.MyClass.sosl()',
1202+
"01:02:03.04 (15)|SOSL_EXECUTE_BEGIN|[1]|FIND 'hello*' IN ALL FIELDS RETURNING account(Id, Name)",
1203+
'01:02:03.04 (16)|SOSL_EXECUTE_END|[1]|Rows:250',
1204+
"01:02:03.04 (17)|SOSL_EXECUTE_BEGIN|[1]|FIND 'hello*' IN ALL FIELDS RETURNING account(Id, Name)",
1205+
'01:02:03.04 (18)|SOSL_EXECUTE_END|[1]|Rows:150',
1206+
'01:02:03.04 (19)|EXCEPTION_THROWN|[60]|System.LimitException: c2g:Too many SOQL queries: 101',
1207+
'01:02:03.04 (20)|METHOD_EXIT|[1]|a00000000000000|ns.MyClass.sosl()',
1208+
'01:02:03.04 (21)|EXCEPTION_THROWN|[60]|System.LimitException: c2g:Too many SOQL queries: 101',
1209+
'01:02:03.04 (22)|EXCEPTION_THROWN|[60]|System.LimitException: c2g:Too many SOQL queries: 101',
1210+
'01:02:03.04 (23)|METHOD_EXIT|[1]|a00000000000000|ns.MyClass.myMethod()',
1211+
'01:02:03.04 (24)|EXECUTION_FINISHED',
1212+
];
1213+
const log1 = logArray.join('\n');
1214+
1215+
const defaultCounts = {
1216+
dmlCount: { total: 0, self: 0 },
1217+
soqlCount: { total: 0, self: 0 },
1218+
soslCount: { total: 0, self: 0 },
1219+
dmlRowCount: { total: 0, self: 0 },
1220+
soqlRowCount: { total: 0, self: 0 },
1221+
soslRowCount: { total: 0, self: 0 },
1222+
totalThrownCount: 0,
1223+
};
1224+
1225+
const apexLog = parse(log1);
1226+
expect(apexLog).toMatchObject(
1227+
// EXECUTION_STARTED
1228+
{
1229+
duration: { total: 24, self: 0 },
1230+
dmlCount: { total: 2, self: 0 },
1231+
soqlCount: { total: 2, self: 0 },
1232+
soslCount: { total: 2, self: 0 },
1233+
dmlRowCount: { total: 5, self: 0 },
1234+
soqlRowCount: { total: 3, self: 0 },
1235+
soslRowCount: { total: 400, self: 0 },
1236+
type: null,
1237+
children: [
1238+
{
1239+
duration: { total: 24, self: 2 },
1240+
dmlCount: { total: 2, self: 0 },
1241+
soqlCount: { total: 2, self: 0 },
1242+
soslCount: { total: 2, self: 0 },
1243+
dmlRowCount: { total: 5, self: 0 },
1244+
soqlRowCount: { total: 3, self: 0 },
1245+
soslRowCount: { total: 400, self: 0 },
1246+
totalThrownCount: 3,
1247+
logLine: logArray[0],
1248+
children: [
1249+
// ns.MyClass.myMethod()
1250+
{
1251+
duration: { total: 22, self: 6 },
1252+
dmlCount: { total: 2, self: 0 },
1253+
soqlCount: { total: 2, self: 0 },
1254+
soslCount: { total: 2, self: 0 },
1255+
dmlRowCount: { total: 5, self: 0 },
1256+
soqlRowCount: { total: 3, self: 0 },
1257+
soslRowCount: { total: 400, self: 0 },
1258+
totalThrownCount: 3,
1259+
logLine: logArray[1],
1260+
children: [
1261+
// ns.MyClass.soql()
1262+
{
1263+
...defaultCounts,
1264+
duration: { total: 5, self: 3 },
1265+
logLine: logArray[2],
1266+
soqlCount: { total: 2, self: 0 },
1267+
soqlRowCount: { total: 3, self: 0 },
1268+
children: [
1269+
//SELECT ID FROM MyObject__c
1270+
{
1271+
...defaultCounts,
1272+
duration: { total: 1, self: 1 },
1273+
soqlCount: { total: 1, self: 1 },
1274+
soqlRowCount: { total: 1, self: 1 },
1275+
logLine: logArray[3],
1276+
},
1277+
// SELECT ID FROM MyObject__c
1278+
{
1279+
...defaultCounts,
1280+
duration: { total: 1, self: 1 },
1281+
soqlCount: { total: 1, self: 1 },
1282+
soqlRowCount: { total: 2, self: 2 },
1283+
logLine: logArray[5],
1284+
},
1285+
],
1286+
},
1287+
// ns.MyClass.dml()
1288+
{
1289+
...defaultCounts,
1290+
duration: { total: 5, self: 3 },
1291+
dmlCount: { total: 2, self: 0 },
1292+
dmlRowCount: { total: 5, self: 0 },
1293+
logLine: logArray[8],
1294+
children: [
1295+
{
1296+
...defaultCounts,
1297+
duration: { total: 1, self: 1 },
1298+
dmlCount: { total: 1, self: 1 },
1299+
dmlRowCount: { total: 1, self: 1 },
1300+
logLine: logArray[9],
1301+
},
1302+
{
1303+
...defaultCounts,
1304+
duration: { total: 1, self: 1 },
1305+
dmlCount: { total: 1, self: 1 },
1306+
dmlRowCount: { total: 4, self: 4 },
1307+
logLine: logArray[11],
1308+
},
1309+
],
1310+
},
1311+
//ns.MyClass.sosl()
1312+
{
1313+
...defaultCounts,
1314+
duration: { total: 6, self: 4 },
1315+
soslCount: { total: 2, self: 0 },
1316+
soslRowCount: { total: 400, self: 0 },
1317+
totalThrownCount: 1,
1318+
logLine: logArray[14],
1319+
children: [
1320+
{
1321+
...defaultCounts,
1322+
duration: { total: 1, self: 1 },
1323+
soslCount: { total: 1, self: 1 },
1324+
soslRowCount: { total: 250, self: 250 },
1325+
totalThrownCount: 0,
1326+
logLine: logArray[15],
1327+
},
1328+
{
1329+
...defaultCounts,
1330+
duration: { total: 1, self: 1 },
1331+
soslCount: { total: 1, self: 1 },
1332+
soslRowCount: { total: 150, self: 150 },
1333+
totalThrownCount: 0,
1334+
logLine: logArray[17],
1335+
},
1336+
// Exception
1337+
{
1338+
...defaultCounts,
1339+
totalThrownCount: 1,
1340+
},
1341+
],
1342+
},
1343+
// Exception
1344+
{
1345+
...defaultCounts,
1346+
totalThrownCount: 1,
1347+
},
1348+
// Exception
1349+
{
1350+
...defaultCounts,
1351+
totalThrownCount: 1,
1352+
},
1353+
],
1354+
},
1355+
],
1356+
},
1357+
],
1358+
},
1359+
);
1360+
});
1361+
});

0 commit comments

Comments
 (0)