Skip to content
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

v0.2.3 issues #285

Closed
ccleve opened this issue Nov 9, 2021 · 14 comments
Closed

v0.2.3 issues #285

ccleve opened this issue Nov 9, 2021 · 14 comments

Comments

@ccleve
Copy link
Contributor

ccleve commented Nov 9, 2021

I happened to upgrade to 0.2.2 earlier today, and 0.2.3 just now. I forced an upgrade to cargo-pgx 0.2.3, built a new, clean app using cargo pgx new, and then copied over the code and [dependencies] section of the cargo.toml. I'm having these issues:

  1. It's way slower than before to run tests. In particular, Building [=====> ] sql_generator(bin) is really slow. What took only a few seconds before now costs 31 seconds (on a really small toy app). cargo pgx run pg13 is also slow to start.

  2. The sample test in lib.rs, test_hello_kestrel(), runs fine. A test in a separate module, however, does not.

/src/pipeline/char_normalizer.rs:

#[cfg(any(test, feature = "pg_test"))]
mod tests {
    use pgx::*;

    #[pg_test]
    fn a_small_test() {
        assert_eq!(2, 2);
    }
}

It fails at: SELECT "tests"."a_small_test"();
function tests.a_small_test() does not exist

Here is the output in all its glory:


ccleve@ccleves-mac-mini kestrel % cargo pgx test pg13
"cargo" "test" "--features" " pg13 pg_test" "--no-default-features"
   Compiling kestrel v0.0.0 (/Users/ccleve/Documents/dev/pgrust/kestrel)
    Finished test [unoptimized + debuginfo] target(s) in 5.01s
     Running unittests (target/debug/deps/kestrel-e0e76a67a435a6c5)

running 2 tests
building extension with features `pg13 pg_test`
"cargo" "build" "--features" "pg13 pg_test" "--no-default-features"
   Compiling kestrel v0.0.0 (/Users/ccleve/Documents/dev/pgrust/kestrel)
    Finished dev [unoptimized + debuginfo] target(s) in 22.63s

installing extension
     Copying control file to `/Users/ccleve/.pgx/13.4/pgx-install/share/postgresql/extension/kestrel.control`
     Copying shared library to `/Users/ccleve/.pgx/13.4/pgx-install/lib/postgresql/kestrel.so`
    Building SQL generator with features `pg13 pg_test`
"cargo" "build" "--bin" "sql-generator" "--features" "pg13 pg_test" "--no-default-features"
    Finished dev [unoptimized + debuginfo] target(s) in 0.13s
 Discovering SQL entities
  Discovered 10 SQL entities: 1 schemas (1 unique), 8 functions, 1 types, 0 enums, 0 sqls, 0 ords, 0 hashes
running SQL generator with features `pg13 pg_test`
"cargo" "run" "--bin" "sql-generator" "--features" "pg13 pg_test" "--no-default-features" "--" "--sql" "/Users/ccleve/.pgx/13.4/pgx-install/share/postgresql/extension/kestrel--1.0.sql"
    Finished dev [unoptimized + debuginfo] target(s) in 0.12s
     Running `target/debug/sql-generator --sql /Users/ccleve/.pgx/13.4/pgx-install/share/postgresql/extension/kestrel--1.0.sql`
     Copying extension schema file to `/Users/ccleve/.pgx/13.4/pgx-install/share/postgresql/extension/kestrel--1.0.sql`
    Finished installing kestrel
test tests::pg_test_hello_kestrel ... ok
test pipeline::char_normalizer::tests::pg_a_small_test ... FAILED

failures:

---- pipeline::char_normalizer::tests::pg_a_small_test stdout ----
thread 'pipeline::char_normalizer::tests::pg_a_small_test' panicked at '
[2021-11-09 16:41:47.353 CST] [12906] [618af92b.326a]: LOG:  starting PostgreSQL 13.4 on x86_64-apple-darwin20.6.0, compiled by Apple clang version 13.0.0 (clang-1300.0.29.3), 64-bit
[2021-11-09 16:41:47.369 CST] [12906] [618af92b.326a]: LOG:  listening on IPv6 address "::1", port 32213
[2021-11-09 16:41:47.369 CST] [12906] [618af92b.326a]: LOG:  listening on IPv4 address "127.0.0.1", port 32213
[2021-11-09 16:41:47.370 CST] [12906] [618af92b.326a]: LOG:  listening on Unix socket "/Users/ccleve/.pgx/.s.PGSQL.32213"
[2021-11-09 16:41:47.387 CST] [12906] [618af92b.326a]: LOG:  database system is ready to accept connections
...
[2021-11-09 16:41:47.750 CST] [12938] [618af92b.328a]: LOG:  statement: BEGIN
[2021-11-09 16:41:47.751 CST] [12938] [618af92b.328a]: LOG:  statement: SELECT "tests"."a_small_test"();
[2021-11-09 16:41:47.751 CST] [12938] [618af92b.328a]: ERROR:  function tests.a_small_test() does not exist at character 8
[2021-11-09 16:41:47.751 CST] [12938] [618af92b.328a]: HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
[2021-11-09 16:41:47.751 CST] [12938] [618af92b.328a]: STATEMENT:  SELECT "tests"."a_small_test"();
[2021-11-09 16:41:47.751 CST] [12938] [618af92b.328a]: LOG:  statement: ROLLBACK

function tests.a_small_test() does not exist
Postgres location: parse_func.c:627
Rust location: <unknown>

', /Users/ccleve/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/pgx-tests-0.2.3/src/framework.rs:118:21
stack backtrace:
   0: rust_begin_unwind
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:515:5
   1: std::panicking::begin_panic_fmt
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:457:5
   2: pgx_tests::framework::run_test
             at /Users/ccleve/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/pgx-tests-0.2.3/src/framework.rs:118:21
   3: kestrel::pipeline::char_normalizer::tests::pg_a_small_test
             at ./src/pipeline/char_normalizer.rs:78:5
   4: kestrel::pipeline::char_normalizer::tests::pg_a_small_test::{{closure}}
             at ./src/pipeline/char_normalizer.rs:78:5
   5: core::ops::function::FnOnce::call_once
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/ops/function.rs:227:5
   6: core::ops::function::FnOnce::call_once
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.


failures:
    pipeline::char_normalizer::tests::pg_a_small_test

test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 25.94s

Stopping Postgres

error: test failed, to rerun pass '--lib'
      [error] cargo pgx test failed with status = Some(101)
ccleve@ccleves-mac-mini kestrel %                                                




@eeeebbbbrrrr
Copy link
Contributor

I'll circle back later today regarding #1, but for #2 is it possible for you to upload a tarball of the crate? I haven't seen tests in other modules fail before, so I don't know exactly what is happing here.

@ccleve
Copy link
Contributor Author

ccleve commented Nov 10, 2021

Let me see if I can reproduce this issue with a very small example.

@eeeebbbbrrrr
Copy link
Contributor

Ya know what, I just figured this out.

the "test" modules need a #[pgx_macros::pg_schema] attribute attached to them. Like so:

#[cfg(any(test, feature = "pg_test"))]
#[pgx_macros::pg_schema]
mod tests {
    use crate::query_dsl::bool::dsl::*;
    use crate::zdbquery::ZDBQuery;
    use pgx::*;
    use serde_json::json;

    // do #[pg_test] functions here
}

@ccleve
Copy link
Contributor Author

ccleve commented Nov 10, 2021

So I completely uninstalled rust, cargo, and pgx, did a clean install, and did a clean "cargo pgx new compiletest", then "cd compiletest", "cargo pgx test pg13". Everything worked fine. I added a new mod and a new test, and it still worked fine.

I went back to my main project, tried to run cargo pgx test pg13, and got this:
https://gist.github.com/ccleve/a1573eace51e0f166845ebad3858fb4c

I'm going to start systematically copying code from the main project to compiletest to see what the difference is.

(And by the way: compile times are still over 30 seconds. I may temporarily downgrade just to get past that problem.)

@eeeebbbbrrrr
Copy link
Contributor

I wonder if your Cargo.toml is wrong. Can you paste it here?

@ccleve
Copy link
Contributor Author

ccleve commented Nov 10, 2021

[package]
name = "kestrel"
version = "0.0.0"
edition = "2018"

[lib]
crate-type = ["cdylib", "rlib"]

[features]
default = ["pg13"]
pg10 = ["pgx/pg10", "pgx-tests/pg10" ]
pg11 = ["pgx/pg11", "pgx-tests/pg11" ]
pg12 = ["pgx/pg12", "pgx-tests/pg12" ]
pg13 = ["pgx/pg13", "pgx-tests/pg13" ]
pg14 = ["pgx/pg14", "pgx-tests/pg14" ]
pg_test = []

[dependencies]
pgx = "0.2.3"
pgx-macros = "0.2.3"
lazy_static = "1.4.0"
unicode-segmentation = "1.8.0"
unicode-normalization = "0.1.19"
serde = { version = "1.0.130", features = ["derive"] }
serde_json = "1.0.69"

[dev-dependencies]
pgx-tests = "0.2.3"

[profile.dev]
panic = "unwind"
lto = "thin"

[profile.release]
panic = "unwind"
opt-level = 3
lto = "fat"
codegen-units = 1

@eeeebbbbrrrr
Copy link
Contributor

That looks good.

hmm

@eeeebbbbrrrr
Copy link
Contributor

I went back to my main project, tried to run cargo pgx test pg13, and got this:

perhaps b/c of all the uninstall/install you did, you need a cargo clean in that crate too.

@ccleve
Copy link
Contributor Author

ccleve commented Nov 10, 2021

I copied most of the main project code to compiletest, and it still works fine.

Tried "cargo clean" on the main project and it still fails in the same way.

Will keep copying code until I find the difference...

@eeeebbbbrrrr
Copy link
Contributor

That looks good.

To clarify, that's the Cargo.toml from the crate that's failing, right?

@ccleve
Copy link
Contributor Author

ccleve commented Nov 10, 2021

Yes. Kestrel fails, compiletest succeeds.

@eeeebbbbrrrr
Copy link
Contributor

try this:

$ cargo pgx schema --force-default

I wonder if your .cargo/config file is out of date relative to the new pgx 0.2.x...

@ccleve
Copy link
Contributor Author

ccleve commented Nov 10, 2021

Bingo. cargo pgx schema --force-default did it. The main project now runs tests successfully. Thank you.

At some point along the way I deleted the .cargo directory, but maybe not recently enough.

Is there some way to do some caching or something to speed up tests?

cargo pgx test pg13
"cargo" "test" "--features" " pg13 pg_test" "--no-default-features"
   Compiling kestrel v0.0.0 (/Users/ccleve/Documents/dev/pgrust/kestrel)
    Finished test [unoptimized + debuginfo] target(s) in 5.40s
     Running unittests (target/debug/deps/kestrel-f8e625f7a60fa19e)

running 2 tests
building extension with features `pg13 pg_test`
"cargo" "build" "--features" "pg13 pg_test" "--no-default-features"
   Compiling kestrel v0.0.0 (/Users/ccleve/Documents/dev/pgrust/kestrel)
    Finished dev [unoptimized + debuginfo] target(s) in 23.61s

(I'll open a new ticket if that helps.)

@eeeebbbbrrrr
Copy link
Contributor

A new ticket about compilation & schema-gen perf would be best.

I'll close this issue as it looks like you're back in action...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants