Closed lsmithso closed 9 years ago
Test database means test keyspace, right? That's expected behavior.
Yes. sorry, I meant test keyspace.
I expect it to work the same way as the relational ORM does. The test db is created at the start of the unit tests, the models are sync'd to it. The unit tests and code under test uses only the test db, and the db is removed at the end of the tests. This way a clean known db state is guaranteed for the tests each time they run. This is transparent to the unit tests and the code under test.
Instead what I'm seeing is that the unit tests and the code under tests uses the live keyspace. This has two major consequences: Sometimes tests fail because unexpected data is in the keyspace, and the test tearDown cleans up data from the live keyspace.
Rafał Furmański writes:
Test database means test keyspace, right? That's expected behavior.
Reply to this email directly or view it on GitHub: https://github.com/r4fek/django-cassandra-engine/issues/15#issuecomment-64465476
Les Smithson
I'm quite sure that test keyspace is using during tests. I'll add proper test tomorrow.
Sorry for not responding earlier. As you can see here: https://github.com/r4fek/django-cassandra-engine/blob/master/testproject/testproject/app/tests/test_models.py#L19 test database is used while running tests. All your models are stored in test keyspace.
Hi: Thanks for your response. How are you running the unit tests? Are you using django-nose?
Rafał Furmański writes:
Sorry for not responding earlier. As you can see here: https://github.com/r4fek/django-cassandra-engine/blob/master/testproject/testproject/app/tests/test_models.py#L19 test database is used while running tests. All your models are stored in test keyspace.
Reply to this email directly or view it on GitHub: https://github.com/r4fek/django-cassandra-engine/issues/15#issuecomment-66872781
Les Smithson
Hi: I replicated this test code in our environment and it doesn't work.
For a ks named "foo", session.set_keyspace("test_foo") results in
InvalidRequest: code=2200 [Invalid query] message="unconfigured columnfamily foo"
Using an explicit TEST_NAME in the db config results in a:
InvalidRequest: code=2200 [Invalid query] message="Keyspace 'xxx_test' does not exist"
We use the django-nose test runner.
Rafał Furmański writes:
Sorry for not responding earlier. As you can see here: https://github.com/r4fek/django-cassandra-engine/blob/master/testproject/testproject/app/tests/test_models.py#L19 test database is used while running tests. All your models are stored in test keyspace.
Reply to this email directly or view it on GitHub: https://github.com/r4fek/django-cassandra-engine/issues/15#issuecomment-66872781
Les Smithson
Hi: I got around to reproducing this exact same test in our environment and it failed with:
InvalidRequest: code=2200 [Invalid query] message="unconfigured columnfamily xxx"
(real cf name redacted)
It would seem that the test keyspace is created but the models are being syncd and connected to the live db, not the test one. When I set the session keyspace to the live db the test passes.
I also introduced a sleep in the test and while it was sleeping checked the tables in the test keyspace using cqlsh. There were none.
Rafał Furmański writes:
Sorry for not responding earlier. As you can see here: https://github.com/r4fek/django-cassandra-engine/blob/master/testproject/testproject/app/tests/test_models.py#L19 test database is used while running tests. All your models are stored in test keyspace.
Reply to this email directly or view it on GitHub: https://github.com/r4fek/django-cassandra-engine/issues/15#issuecomment-66872781
Les Smithson
Hi, Sorry for such long wait. Please provide me more details about your test environment (TEST_RUNNER, TestCase, what packages are installed, how tests are launched, etc.). I'm unable to reproduce this and that's why I need more information.
Hi: I've had some time to look at this again and discovered that the test model used in the test cases hard codes keyspace to "test_db", so test_db is used even when the test keyspace isn't being set up . Setting keyspace = "db" makes all of the test fail because django-cassandra-engine is not setting the model's keyspace to test_db.
Would it work to have create_test_db update all the model's keyspace attrs before calling sync_table?
Rafał Furmański writes: > Hi, > Sorry for such long wait. > Please provide me more details about your test environment (TEST_RUNNER, TestCase, what packages are installed, how tests are launched, etc.). I'm unable to reproduce this and that's why I need more information.
Reply to this email directly or view it on GitHub: https://github.com/r4fek/django-cassandra-engine/issues/15#issuecomment-68434900
Les Smithson
Just to make it clear - its the django-cassandra-engine tests that set keyspace to "test_db", and that fail if keyspace is set to "db".
Rafał Furmański writes:
Hi, Sorry for such long wait. Please provide me more details about your test environment (TEST_RUNNER, TestCase, what packages are installed, how tests are launched, etc.). I'm unable to reproduce this and that's why I need more information.
Reply to this email directly or view it on GitHub: https://github.com/r4fek/django-cassandra-engine/issues/15#issuecomment-68434900
Les Smithson
Should be fixed now. Closing.
when running units tests the code under test reads and writes to the live database not the test one even though the log says the test database is created and models synced to it.