In issue #10767, concerned were raised that the CLUSTERING ORDER BY clause is handled incorrectly in a CREATE MATERIALIZED VIEW definition. The tests in this patch try to explore the different ways in which CLUSTERING ORDER BY can be used in CREATE MATERIALIZED VIEW and allows us to compare Scylla's behaivor to Cassandra, and to common sense. The tests discover that the CLUSTERING ORDER BY feature in materialized views generally works as expected, but there are *three* differences between Scylla and Cassandra in this feature. We consider two differences to be bugs (and hence the test is marked xfail) and one a Scylla extension: 1. When a base table has a reverse-order clustering column and this clustering column is used in the materialized view, in Cassandra the view's clustering order inherits the reversed order. In Scylla, the view's clustering order reverts to the default order. Arguably, both behaviors can be justified, but usually when in doubt we should implement Cassandra's behavior - not pick a different behavior, even if the different behavior is also reasonable. So this test (test_mv_inherit_clustering_order()) is marked "xfail", and a new issue was created about this difference: #12308. If we want to fix this behavior to match Cassandra's we should also consider backward compatibility - what happens if we change this behavior in Scylla now, after we had the opposite behavior in previous releases? We may choose to enshrine Scylla's Cassandra- incompatible behavior here - and document this difference. 2. The CLUSTERING ORDER BY should, as its name suggests, only list clustering columns. In Scylla, specifying other things, like regular columns, partition-key columns, or non-existent columns, is silently ignored, whereas it should result in an Invalid Request error (as it does in Cassandra). So test_mv_override_clustering_order_error() is marked "xfail". This is the difference already discovered in #10767. 3. When a materialized view has several clustering columns, Cassandra requires that a CLUSTERING ORDER BY clause, if present, must specify the order of all of *all* clustering columns. Scylla, in contrast, allows the user to override the order of only *some* of these columns - and the rest get the default order. I consider this to be a legitimate Scylla extension, and not a compatibility bug, so marked the test with "scylla_only", and no issue was opened about it. Refs #10767 Refs #12308 Signed-off-by: Nadav Har'El <nyh@scylladb.com> Closes #12307
Single-node functional tests for Scylla's CQL features.
These tests use the Python CQL library and the pytest frameworks. By using an actual CQL library for the tests, they can be run against any implementation of CQL - both Scylla and Cassandra. Most tests - except in rare cases - should pass on both, to ensure that Scylla is compatible with Cassandra in most features.
To run all tests against an already-running local installation of Scylla
or Cassandra on localhost, just run pytest. The "--host" and "--port"
can be used to give a different location for the running Scylla or Cassanra.
The "--ssl" option can be used to use an encrypted (TLSv1.2) connection.
More conveniently, we have two scripts - "run" and "run-cassandra" - which do all the work necessary to start Scylla or Cassandra (respectively), and run the tests on them. The Scylla or Cassandra process is run in a temporary directory which is automatically deleted when the test ends.
"run" automatically picks the most recently compiled version of Scylla in
build/*/scylla - but this choice of Scylla executable can be overridden with
the SCYLLA environment variable. "run-cassandra" defaults to running the
command cassandra from the user's path, but this can be overriden by setting
the CASSANDRA environment variable to the path of the cassandra script,
e.g., export CASSANDRA=$HOME/apache-cassandra-3.11.10/bin/cassandra.
A few of the tests also require the nodetool when running on Cassandra -
this tool is again expected to be in the user's path, or be overridden with
the NODETOOL environment variable. Nodetool is not needed to test
Scylla.
Additional options can be passed to "pytest" or to "run" / "run-cassandra" to control which tests to run:
- To run all tests in a single file, do
pytest test_table.py. - To run a single specific test, do
pytest test_table.py::test_create_table_unsupported_names. - To run the same test or tests 100 times, add the
--count=100option. This is faster than runningrun100 times, because Scylla is only run once, and also counts for you how many of the runs failed. Forpytestto support the--countoption, you need to install a pytest extension:pip install pytest-repeat
Additional useful pytest options, especially useful for debugging tests:
- -v: show the names of each individual test running instead of just dots.
- -s: show the full output of running tests (by default, pytest captures the test's output and only displays it if a test fails)