mojolicious / mojo-pg

Mojolicious :heart: PostgreSQL
https://metacpan.org/release/Mojo-Pg
Artistic License 2.0
101 stars 46 forks source link

Tests appear to be horked if you're a new contributor #41

Closed shadowcat-mst closed 6 years ago

shadowcat-mst commented 7 years ago

Steps to reproduce the behavior

Try and run the tests with TEST_ONLINE=postgresql:///some_db_name

Expected behavior

Tests run

Actual behavior

Everything dies because the tests tries to set search_path to nonexistant schemas

e.g. from t/migrations.t

Isolate tests

my $pg
  = Mojo::Pg->new($ENV{TEST_ONLINE})->search_path(['mojo_migrations_test']);
$pg->db->query('drop schema if exists mojo_migrations_test cascade');
$pg->db->query('create schema mojo_migrations_test');

but that isn't valid with no such schema already existing, which it doesn't when I just created a fresh database for testing Mojo::Pg against and thus:

DBD::Pg::db do failed: ERROR:  invalid value for parameter "search_path": "mojo_migrations_test"
DETAIL:  schema "mojo_migrations_test" does not exist at /home/matthewt/tmp/mojo-pg/lib/Mojo/Pg.pm line 83.
t/migrations.t .. 
Dubious, test returned 255 (wstat 65280, 0xff00)
No subtests run 

Test Summary Report
-------------------
t/migrations.t (Wstat: 65280 Tests: 0 Failed: 0)
  Non-zero exit status: 255
  Parse errors: No plan found in TAP output
Files=1, Tests=0,  1 wallclock secs ( 0.01 usr  0.02 sys +  0.28 cusr  0.02 csys =  0.33 CPU)
Result: FAIL

Basically so far as I can tell you can't run the tests against any database you didn't ... already run the tests against.

That probably wouldn't be too terrible to fix, but also I'm not even sure where the foo and bar schemas are supposed to come from for t/database.t so I didn't think patching blindly seemed like a good idea.

Am I missing something here or is this horked?

kraih commented 7 years ago

Wouldn't Travis testing be borked too then? https://travis-ci.org/kraih/mojo-pg

kraih commented 7 years ago

Perhaps it's a new feature in recent versions of Postgres, on IRC we've had reports that it works from at least 9.4 onwards.

ilmari commented 7 years ago

PostgreSQL versions before 9.2 throw an error when setting search_path to a non-existent schema:

$ pg_lsclusters -h|while read v n rest; do echo -n "$v: "; psql -X --cluster $v/$n -c 'set search_path to no_such_schema'; done
8.4: ERROR:  schema "no_such_schema" does not exist
9.0: ERROR:  schema "no_such_schema" does not exist
9.1: ERROR:  invalid value for parameter "search_path": "no_such_schema"
DETAIL:  schema "no_such_schema" does not exist
9.2: SET
9.3: SET
9.4: SET
9.5: SET
9.6: SET
kraih commented 7 years ago

That means it works for at least all versions of PostgreSQL that have not reached their EOL date. https://www.postgresql.org/support/versioning/

ilmari commented 7 years ago

Yes. @shadowcat-mst appears to be running Debian 7 (wheezy), which is also EOLed (except for limited LTS).

shadowcat-mst commented 7 years ago

I tend to test against the oldest version of things I still have to live with in production.

If Mojo::Pg explicitly doesn't support earlier versions, could it at least die() on connect with a useful error or something?

niczero commented 7 years ago

I wouldn't want a 'die', but it would be useful if the test script had a helpful 'diag'.

niczero commented 7 years ago

@shadowcat-mst: if you have a min, could you adjust the title of this issue now it's clear it's not about new contributors, but about using old databases.

kraih commented 6 years ago

Looks like this issue went stale.

ilmari commented 6 years ago

The trivial fix for this would be to move the ->search_path call to after the DROP/CREATE schema. Or, if that only affects new connections, use ->query('SET search_path TO …') instead.