-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: ensure cleanup of sqlite3 db files after test #8393
Conversation
Oh... seems like SQLite3 tests are failing now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PHPUnit 9.6.15 by Sebastian Bergmann and contributors.
Runtime: PHP 7.4.33
Configuration: /home/runner/work/CodeIgniter4/CodeIgniter4/phpunit.xml.dist
..S............................................................ 63 / 667 ( 9%)
...............S.S...S...........S............................. 126 / 667 ( 18%)
............................................................... 189 / 667 ( 28%)
......SSSSSSSSSSSSSSSSS.........................EEEEEEEEEEEEEEE 252 / 667 ( 37%)
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE 315 / 667 ( 47%)
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE 378 / 667 ( 56%)
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE 441 / 667 ( 66%)
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE... 504 / 667 ( 75%)
.....EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE 567 / 667 ( 85%)
EEEEEEEEEEEEEEEEEEEEEEEEEEE.................................... 630 / 667 ( 94%)
.............EEEEEEEEEEEEEEEEEEEEEEEE 667 / 667 (100%)
Time: 00:10.854, Memory: 94.00 MB
There were 373 errors:
1) CodeIgniter\Database\Live\SelectTest::testSelectAllByDefault
CodeIgniter\Database\Exceptions\DatabaseException: SQLite3::exec(): attempt to write a readonly database
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/BaseConnection.php:647
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/Forge.php:637
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/_support/Database/Migrations/20160428212500_Create_test_tables.php:165
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/MigrationRunner.php:865
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/MigrationRunner.php:288
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Test/DatabaseTestTrait.php:134
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Test/DatabaseTestTrait.php:103
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Test/DatabaseTestTrait.php:55
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Test/CIUnitTestCase.php:249
phpvfscomposer:///home/runner/work/CodeIgniter4/CodeIgniter4/vendor/phpunit/phpunit/phpunit:106
Caused by
CodeIgniter\Database\Exceptions\DatabaseException: SQLite3::exec(): attempt to write a readonly database
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/SQLite3/Connection.php:151
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/BaseConnection.php:693
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/BaseConnection.php:607
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/Forge.php:637
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/_support/Database/Migrations/20160428212500_Create_test_tables.php:165
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/MigrationRunner.php:865
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/MigrationRunner.php:288
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Test/DatabaseTestTrait.php:134
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Test/DatabaseTestTrait.php:103
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Test/DatabaseTestTrait.php:55
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Test/CIUnitTestCase.php:249
phpvfscomposer:///home/runner/work/CodeIgniter4/CodeIgniter4/vendor/phpunit/phpunit/phpunit:106
Caused by
ErrorException: SQLite3::exec(): attempt to write a readonly database
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/SQLite3/Connection.php:145
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/BaseConnection.php:693
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/BaseConnection.php:607
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/Forge.php:637
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/_support/Database/Migrations/20160428212500_Create_test_tables.php:165
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/MigrationRunner.php:865
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/MigrationRunner.php:288
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Test/DatabaseTestTrait.php:134
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Test/DatabaseTestTrait.php:103
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Test/DatabaseTestTrait.php:55
/home/runner/work/CodeIgniter4/CodeIgniter4/system/Test/CIUnitTestCase.php:249
phpvfscomposer:///home/runner/work/CodeIgniter4/CodeIgniter4/vendor/phpunit/phpunit/phpunit:106
To begin with, DatabaseLive tests fail in $ vendor/bin/phpunit --group DatabaseLive
PHPUnit 9.6.15 by Sebastian Bergmann and contributors.
Runtime: PHP 8.2.13
Configuration: /Users/kenji/work/codeigniter/official/CodeIgniter4/phpunit.xml
..S...........................................................................S.S...S...........S.......... 107 / 667 ( 16%)
........................................................................................SSSSSSSSSSSSSSSSS.. 214 / 667 ( 32%)
........................................EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE 321 / 667 ( 48%)
EEEEEEEEEEEEEEEEEEEE...............................EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE 428 / 667 ( 64%)
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE........EEEEEEEEEEEEEEEEEEEEEEEEEE 535 / 667 ( 80%)
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE.....EEEEE.E.................................... 642 / 667 ( 96%)
.EEEEEEEEEEEEEEEEEEEEEEEE 667 / 667 (100%)
Time: 00:11.947, Memory: 102.00 MB
There were 331 errors:
1) CodeIgniter\Database\Live\TransactionDBDebugFalseTest::testTransStartTransException
CodeIgniter\Database\Exceptions\DatabaseException: SQLite3::exec(): no such table: db_user
/Users/kenji/work/codeigniter/official/CodeIgniter4/system/Database/BaseConnection.php:647
/Users/kenji/work/codeigniter/official/CodeIgniter4/system/Database/BaseBuilder.php:2712
/Users/kenji/work/codeigniter/official/CodeIgniter4/tests/_support/Database/Seeds/CITestSeeder.php:180
/Users/kenji/work/codeigniter/official/CodeIgniter4/system/Database/Seeder.php:145
/Users/kenji/work/codeigniter/official/CodeIgniter4/system/Test/DatabaseTestTrait.php:205
/Users/kenji/work/codeigniter/official/CodeIgniter4/system/Test/DatabaseTestTrait.php:193
... |
I thought this was on my machine only. The failing test is saying |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welp, I approved before I saw test results and the discussion 🤦♂️ Code looks good though, haha!
👋 Hi, @paulbalandan! |
@paulbalandan I found the cause. #8447 |
873c932
to
6636137
Compare
30bfaa3
to
84134b8
Compare
I am really confused why changes to SQLite break tests on linux but not on macos. |
|
||
if (is_file(WRITEPATH . 'database.db')) { | ||
unlink(WRITEPATH . 'database.db'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should not remove the database file in use.
It causes "SQLite3::exec(): attempt to write a readonly database"
because the file is gone, but the connection remains.
Try:
Set database.tests.database = database.db
and
$ vendor/bin/phpunit tests/system/Database/
I think we don't need to remove |
Yes, or it could be that there are lingering shared DB connections used by the next test instead of creating a new one. Based on the stack trace, the error comes from |
We use the shared DB connection during all tests by default. CodeIgniter4/system/Test/DatabaseTestTrait.php Lines 72 to 74 in 65c6692
I think reconnecting for each test class would slow down the tests. |
👋 Hi, @paulbalandan! |
84134b8
to
c85cd6d
Compare
|
Description
Currently,
writable/
has two leftover DB files from sqlite3:database.db
andrunner.sqlite
. This PR cleans them.Checklist: