[
https://issues.apache.org/jira/browse/CALCITE-2484?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Caizhi Weng updated CALCITE-2484:
---------------------------------
Description:
h2. What's happening
When two dynamic table tests referencing to the same table name run
concurrently, the results of the tests will be incorrect, causing the tests to
fail.
h2. How to reproduce this bug
As the condition to trigger this bug is strict (two dynamic table tests must
reference the same table name, and they must run concurrently), it's hard to
reproduce this bug in the current test set.
I construct two mock test classes to reproduce this bug stably. The two test
classes are the same except for their names. One of the test class is listed as
follows:
{code:java}
public class MockSqlValidatorTest1 extends SqlValidatorTestCase {
// Member definition omitted.
@Test
public void testDynamicStar1() {
final String sql = "select newid from (\n"
+ " select *, NATION.N_NATION + 100 as newid\n"
+ " from \"DYNAMIC\".NATION, \"DYNAMIC\".CUSTOMER)";
sql(sql).type("RecordType(ANY NEWID) NOT NULL");
}
@Test
public void testDynamicStar2() {
final String sql = "select newid from (\n"
+ " select *, NATION.N_NATION + 100 as newid\n"
+ " from \"DYNAMIC\".NATION, \"DYNAMIC\".CUSTOMER)";
sql(sql).type("RecordType(ANY NEWID) NOT NULL");
}
// 296 more test cases
@Test
public void testDynamicStar299() {
final String sql = "select newid from (\n"
+ " select *, NATION.N_NATION + 100 as newid\n"
+ " from \"DYNAMIC\".NATION, \"DYNAMIC\".CUSTOMER)";
sql(sql).type("RecordType(ANY NEWID) NOT NULL");
}
@Test
public void testDynamicStar300() {
final String sql = "select newid from (\n"
+ " select *, NATION.N_NATION + 100 as newid\n"
+ " from \"DYNAMIC\".NATION, \"DYNAMIC\".CUSTOMER)";
sql(sql).type("RecordType(ANY NEWID) NOT NULL");
}
{code}
You can check these two test classes
[here|https://paste.ubuntu.com/p/rcWYjMzMjf/] and
[here|https://paste.ubuntu.com/p/Tb2VTz74Xv/] so you can try them out.
To reproduce this bug, run
{code}
mvn -T 4 -Dtest=MockSqlValidatorTest* test -pl core
{code}
to run these two test classes concurrently, the bug will occur.
h2. Why is this happening
# In the current implementation, when a test class wants to use a
{{SqlTestFactory}}, it will use {{SqlTestFactory.INSTANCE}}, so every class
using this factory actually shares the same factory instance.
# {{catalogReader}} is a member of {{SqlTestFactory}}, so every class actually
shares the same {{catalogReader}}.
# As root schema is stored in catalog reader, table is stored in root schema,
and row type is stored in table, every class actually has access to the same
row type instance.
# As dynamic table will modify row type if a column name it wants to use
doesn't exist, two test cases running concurrently and using the same table
name may read and modify the same row type instance, causing the result of the
test to be incorrect, thus causing the failure of the test.
h2. How to fix this bug
What I've done in this commit is to remove {{SqlTestFactory.INSTANCE}}, and let
every test class use a new instance of the factory, so that we can solve the
concurrent modification problem.
was:
h2. What's happening
When two dynamic table tests referencing to the same table name run
concurrently, the results of the tests will be incorrect, causing the tests to
fail.
h2. How to reproduce this bug
As the condition to trigger this bug is strict (two dynamic table tests must
reference the same table name, and they must run concurrently), it's hard to
reproduce this bug in the current test set.
I construct two mock test classes to reproduce this bug stably. The two test
classes are the same except for their names. One of the test class is listed as
follows:
{code:java}
public class MockSqlValidatorTest1 extends SqlValidatorTestCase {
// Member definition omitted.
@Test
public void testDynamicStar1() {
final String sql = "select newid from (\n"
+ " select *, NATION.N_NATION + 100 as newid\n"
+ " from \"DYNAMIC\".NATION, \"DYNAMIC\".CUSTOMER)";
sql(sql).type("RecordType(ANY NEWID) NOT NULL");
}
@Test
public void testDynamicStar2() {
final String sql = "select newid from (\n"
+ " select *, NATION.N_NATION + 100 as newid\n"
+ " from \"DYNAMIC\".NATION, \"DYNAMIC\".CUSTOMER)";
sql(sql).type("RecordType(ANY NEWID) NOT NULL");
}
// 296 more test cases
@Test
public void testDynamicStar299() {
final String sql = "select newid from (\n"
+ " select *, NATION.N_NATION + 100 as newid\n"
+ " from \"DYNAMIC\".NATION, \"DYNAMIC\".CUSTOMER)";
sql(sql).type("RecordType(ANY NEWID) NOT NULL");
}
@Test
public void testDynamicStar300() {
final String sql = "select newid from (\n"
+ " select *, NATION.N_NATION + 100 as newid\n"
+ " from \"DYNAMIC\".NATION, \"DYNAMIC\".CUSTOMER)";
sql(sql).type("RecordType(ANY NEWID) NOT NULL");
}
{code}
> Dynamic table tests give wrong results when running tests concurrently.
> -----------------------------------------------------------------------
>
> Key: CALCITE-2484
> URL: https://issues.apache.org/jira/browse/CALCITE-2484
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.17.0
> Reporter: Caizhi Weng
> Assignee: Julian Hyde
> Priority: Major
> Fix For: 1.18.0
>
>
> h2. What's happening
> When two dynamic table tests referencing to the same table name run
> concurrently, the results of the tests will be incorrect, causing the tests
> to fail.
> h2. How to reproduce this bug
> As the condition to trigger this bug is strict (two dynamic table tests must
> reference the same table name, and they must run concurrently), it's hard to
> reproduce this bug in the current test set.
> I construct two mock test classes to reproduce this bug stably. The two test
> classes are the same except for their names. One of the test class is listed
> as follows:
> {code:java}
> public class MockSqlValidatorTest1 extends SqlValidatorTestCase {
> // Member definition omitted.
> @Test
> public void testDynamicStar1() {
> final String sql = "select newid from (\n"
> + " select *, NATION.N_NATION + 100 as newid\n"
> + " from \"DYNAMIC\".NATION, \"DYNAMIC\".CUSTOMER)";
> sql(sql).type("RecordType(ANY NEWID) NOT NULL");
> }
> @Test
> public void testDynamicStar2() {
> final String sql = "select newid from (\n"
> + " select *, NATION.N_NATION + 100 as newid\n"
> + " from \"DYNAMIC\".NATION, \"DYNAMIC\".CUSTOMER)";
> sql(sql).type("RecordType(ANY NEWID) NOT NULL");
> }
> // 296 more test cases
> @Test
> public void testDynamicStar299() {
> final String sql = "select newid from (\n"
> + " select *, NATION.N_NATION + 100 as newid\n"
> + " from \"DYNAMIC\".NATION, \"DYNAMIC\".CUSTOMER)";
> sql(sql).type("RecordType(ANY NEWID) NOT NULL");
> }
> @Test
> public void testDynamicStar300() {
> final String sql = "select newid from (\n"
> + " select *, NATION.N_NATION + 100 as newid\n"
> + " from \"DYNAMIC\".NATION, \"DYNAMIC\".CUSTOMER)";
> sql(sql).type("RecordType(ANY NEWID) NOT NULL");
> }
> {code}
> You can check these two test classes
> [here|https://paste.ubuntu.com/p/rcWYjMzMjf/] and
> [here|https://paste.ubuntu.com/p/Tb2VTz74Xv/] so you can try them out.
> To reproduce this bug, run
> {code}
> mvn -T 4 -Dtest=MockSqlValidatorTest* test -pl core
> {code}
> to run these two test classes concurrently, the bug will occur.
> h2. Why is this happening
> # In the current implementation, when a test class wants to use a
> {{SqlTestFactory}}, it will use {{SqlTestFactory.INSTANCE}}, so every class
> using this factory actually shares the same factory instance.
> # {{catalogReader}} is a member of {{SqlTestFactory}}, so every class
> actually shares the same {{catalogReader}}.
> # As root schema is stored in catalog reader, table is stored in root schema,
> and row type is stored in table, every class actually has access to the same
> row type instance.
> # As dynamic table will modify row type if a column name it wants to use
> doesn't exist, two test cases running concurrently and using the same table
> name may read and modify the same row type instance, causing the result of
> the test to be incorrect, thus causing the failure of the test.
> h2. How to fix this bug
> What I've done in this commit is to remove {{SqlTestFactory.INSTANCE}}, and
> let every test class use a new instance of the factory, so that we can solve
> the concurrent modification problem.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)