[5.2] Fix Postgres Problem in our testing#44303
[5.2] Fix Postgres Problem in our testing#44303rdeutz wants to merge 8 commits intojoomla:5.2-devfrom
Conversation
tests/System/integration/administrator/components/com_privacy/Consent.cy.js
Outdated
Show resolved
Hide resolved
|
From my point of view, it would be more beneficial to perform the cleanup in Regarding the failing System Tests with the error |
tests/System/integration/administrator/components/com_privacy/Consent.cy.js
Outdated
Show resolved
Hide resolved
…Consent.cy.js Co-authored-by: Richard Fath <richard67@users.noreply.github.com>
Makes sense
The cleanupDB is a good idea, haven't looked at the test for a longer time and didn't noticed this. But as far as I understand it it runs only after a block and not after a single test. So my guess is that this will not help. |
|
@rdeutz @richard67 @laoneo @alikon @LadySolveig I am now happy 😄 to be able to consistently reproduce the PostgreSQL scripts/create 52 pgsql
cat > branch_52/tests/System/integration/install/duplicate.cy.js <<EOF
describe('Test duplicate key value error', () => {
it('in creating 1,000 users', () => {
for (let i = 1; i <= 1000; i++) {
cy.db_createUser({username: \`test user \${i}\` });
}
});
});
EOF
scripts/test 52 system install/duplicate.cy.js Results in: Curiously, it only works on a fresh database. So for the next tests, you have to create a new one (it only takes about a minute): scripts/database 52 pgsql
scripts/test 52 system install/duplicate.cy.jsTherefore, it seems the issue is not related to the To remember we have seen it most times on My question is: should this be solved in System Tests only with a table lock, using transactions, or maybe just a small wait? Or is it a bigger issue that requires a solution like using DEFERRABLE when creating the table? Are there other tools, such as importing mass data, that could have the problem too? |
|
@muhme But shouldn't that already be solved when this change is made here? Then the table is always emptied before the test runs and we don't have the problem if the test is cancelled? Could you perhaps rerun your test with this change to see if this could solve the problem very easy. |
That could mean we have some problem with the initial value of a sequence on a new installation, possibly not only for the system tests bit in general, and it just hasn’t been noticed yet. Hard to believe, but who knows? @muhme What happens if you manually do on a new installation what the system test does? |
@LadySolveig From my point of view, this is not a duplicate in the unique |
JBT's |
|
@muhme yes, now i have understood what you mean. 👍🏼 Sorry that I didn't read more carefully. I think the approach to test if there is something fundamentally wrong on the testing system for postgrees as @richard67 mentioned would be advisable in any case. But quite apart from that, I think we should consider the switch to onBefore for resetting the data. |
|
I was wondering how user creation works from the command-line tool on a fresh database: for i in {1..10000}; do
echo "INSERT INTO jos52_users (username, name, email, password, \"registerDate\", params) VALUES ('user $i', 'test', 'test@example.com', '098f6bcd4621d373cade4e832627b4f6', NOW(), '' );" >> /tmp/a.sql
done
scripts/database 52 pgsql
docker cp /tmp/a.sql jbt_pg:/tmp/a.sql
docker exec jbt_pg bash -c "PGPASSWORD=root psql -U root -d test_joomla_52 -f /tmp/a.sql"
|
|
if you run the but the sequence value is still 1 describe('Test duplicate key value error', () => {
it('in creating 1,000 users', () => {
for (let i = 1; i <= 1000; i++) {
cy.db_createUser({username: \`test user \${i}\` });
}
});
});for avoid this you need to change the script it('in creating 1,000 users', () => {
cy.task('queryDB', `SELECT MAX(id) +1 as id FROM #__users`)
.then((id) => {
console.log('id:', id[0].id);
cy.task('queryDB', `SELECT setval('#__users_id_seq', ${id[0].id}, false)`)
})
for (let i = 1; i <= 1000; i++) {
cy.db_createUser({username: `test user ${i}` });
}
});so the problem is that the sequence value is not updated correctly after the creation of the SUperUser |
|
please check #44324 should fix the issue with postgresql duplicate key |
|
Do we still need this one as #44324 fixes the problem? |
|
Thank you, Nicola for open our eyes 👍 With that insight, I now realize I was wrong whith:
Of course, this fails as well, but I didn't notice it yesterday in the 10,000 lines of output. It's better to run with: docker exec jbt_pg bash -c "PGPASSWORD=root psql -U root -d test_joomla_52 --set ON_ERROR_STOP=on -f /tmp/a.sqlAnd then, of course, we see the result: ...
INSERT 0 1
INSERT 0 1
INSERT 0 1
psql:/tmp/a.sql:263: ERROR: duplicate key value violates unique constraint "jos52_users_pkey"
DETAIL: Key (id)=(263) already exists.MariaDB and MySQL do not have the problem, they continue on their own with the following ID. |
|
Again, do we still need this PR? |
|
Summary of Changes
Clean up the data in a different way.