Skip to content

Commit cf6a83e

Browse files
committed
standardize postgres error loggs
1 parent 23a19f3 commit cf6a83e

File tree

5 files changed

+29
-8
lines changed

5 files changed

+29
-8
lines changed

src/sqlancer/ComparatorHelper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public static void assumeResultSetsAreEqual(List<String> resultSet, List<String>
9191
combinedString.stream().collect(Collectors.joining(";")), secondResultSet.size());
9292
state.getState().statements.add(new QueryAdapter(firstQueryString));
9393
state.getState().statements.add(new QueryAdapter(secondQueryString));
94+
state.getState().queryString = String.format("%s\n%s", firstQueryString, secondQueryString);
9495
String assertionMessage = String.format("the size of the result sets mismatch (%d and %d)!\n%s\n%s",
9596
resultSet.size(), secondResultSet.size(), firstQueryString, secondQueryString);
9697
throw new AssertionError(assertionMessage);
@@ -104,12 +105,13 @@ public static void assumeResultSetsAreEqual(List<String> resultSet, List<String>
104105
firstResultSetMisses.removeAll(secondHashSet);
105106
Set<String> secondResultSetMisses = new HashSet<>(secondHashSet);
106107
secondResultSetMisses.removeAll(firstHashSet);
107-
String queryFormatString = "%s; -- misses: %s";
108+
String queryFormatString = "--%s;\n-- misses: %s";
108109
String firstQueryString = String.format(queryFormatString, originalQueryString, firstResultSetMisses);
109110
String secondQueryString = String.format(queryFormatString,
110111
combinedString.stream().collect(Collectors.joining(";")), secondResultSetMisses);
111112
state.getState().statements.add(new QueryAdapter(firstQueryString));
112113
state.getState().statements.add(new QueryAdapter(secondQueryString));
114+
state.getState().queryString = String.format("%s\n%s", firstQueryString, secondQueryString);
113115
String assertionMessage = String.format("the content of the result sets mismatch!\n%s\n%s",
114116
firstQueryString, secondQueryString);
115117
throw new AssertionError(assertionMessage);

src/sqlancer/StateToReproduce.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
public class StateToReproduce {
2121

2222
public final List<Query> statements = new ArrayList<>();
23+
24+
/**
25+
* The string printed at the bottom of the error log file, which contains
26+
* the queries that caused the test to fail and information about their results.
27+
*/
2328
public String queryString;
2429

2530
private final String databaseName;

src/sqlancer/postgres/oracle/PostgresNoRECOracle.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,14 @@ public void check() throws SQLException {
7878
throw new IgnoreMeException();
7979
}
8080
if (firstCount != secondCount) {
81-
state.queryString = firstCount + " " + secondCount + " " + firstQueryString + ";\n" + secondQueryString
82-
+ ";";
83-
throw new AssertionError(firstQueryString + secondQueryString + firstCount + " " + secondCount);
81+
String queryFormatString = "%s; -- count: %d";
82+
String firstQueryStringWithCount = String.format(queryFormatString, firstQueryString, firstCount);
83+
String secondQueryStringWithCount = String.format(queryFormatString, secondQueryString, secondCount);
84+
state.statements.add(new QueryAdapter(firstQueryStringWithCount));
85+
state.statements.add(new QueryAdapter(secondQueryStringWithCount));
86+
state.queryString = String.format("%s\n%s", firstQueryStringWithCount, secondQueryStringWithCount);
87+
String assertionMessage = String.format("the counts mismatch (%d and %d)!\n%s\n%s", firstCount, secondCount, firstQueryStringWithCount, secondQueryStringWithCount);
88+
throw new AssertionError(assertionMessage);
8489
}
8590
}
8691

src/sqlancer/postgres/oracle/PostgresPivotedQuerySynthesisOracle.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import sqlancer.postgres.ast.PostgresSelect;
2828
import sqlancer.postgres.ast.PostgresSelect.PostgresFromTable;
2929
import sqlancer.postgres.gen.PostgresExpressionGenerator;
30+
import sqlancer.QueryAdapter;
3031

3132
public class PostgresPivotedQuerySynthesisOracle implements TestOracle {
3233

@@ -57,7 +58,9 @@ public void check() throws SQLException {
5758

5859
boolean isContainedIn = isContainedIn(queryString, options, logger);
5960
if (!isContainedIn) {
60-
throw new AssertionError(queryString);
61+
state.statements.add(new QueryAdapter(queryString));
62+
String assertionMessage = String.format("the query doesn't contain at least 1 row!\n%s", queryString);
63+
throw new AssertionError(assertionMessage);
6164
}
6265

6366
}

src/sqlancer/postgres/oracle/tlp/PostgresTLPAggregateOracle.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,21 @@ public void check() throws SQLException {
6363
metamorphicQuery = createMetamorphicUnionQuery(select, aggregate, select.getFromList());
6464
secondResult = getAggregateResult(metamorphicQuery);
6565

66-
state.getState().queryString = "--" + originalQuery + ";\n--" + metamorphicQuery + "\n-- " + firstResult
67-
+ "\n-- " + secondResult;
66+
String queryFormatString = "--%s;\n-- result: %s";
67+
String firstQueryString = String.format(queryFormatString, originalQuery, firstResult);
68+
String secondQueryString = String.format(queryFormatString, metamorphicQuery, secondResult);
69+
state.getState().statements.add(new QueryAdapter(firstQueryString));
70+
state.getState().statements.add(new QueryAdapter(secondQueryString));
71+
state.getState().queryString = String.format("%s\n%s", firstQueryString, secondQueryString);
6872
if (firstResult == null && secondResult != null
6973
|| firstResult != null && (!firstResult.contentEquals(secondResult)
7074
&& !ComparatorHelper.isEqualDouble(firstResult, secondResult))) {
7175
if (secondResult.contains("Inf")) {
7276
throw new IgnoreMeException(); // FIXME: average computation
7377
}
74-
throw new AssertionError();
78+
String assertionMessage = String.format("the results mismatch!\n%s\n%s",
79+
firstQueryString, secondQueryString);
80+
throw new AssertionError(assertionMessage);
7581
}
7682

7783
}

0 commit comments

Comments
 (0)