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

Poly 261 - Classpath stability for tests #1

Merged
merged 2 commits into from
May 8, 2023
Merged

Poly 261 - Classpath stability for tests #1

merged 2 commits into from
May 8, 2023

Conversation

ieugen
Copy link
Owner

@ieugen ieugen commented May 8, 2023

Reproducer for polyfy/polylith#261

Running test will fail sqldb test with second project.
Why do we have to run component tests multiple times?

clojure -M:poly test
clojure/poly-rcf$ clojure -M:poly test
Projects to run tests from: poly261, rcf

Running tests for the poly261 project using test runner: Polylith built-in clojure.test runner...
Running tests from the poly261 project, including 2 bricks: sqldb, issue-261

Testing poly-rcf.rcf.issue-261.core-test

Ran 1 tests containing 1 assertions.
0 failures, 0 errors.

Test results: 1 passes, 0 failures, 0 errors.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

Testing poly-rcf.rcf.sqldb.interface-test

Ran 1 tests containing 1 assertions.
0 failures, 0 errors.

Test results: 1 passes, 0 failures, 0 errors.

Testing poly-rcf.rcf.sqldb.interface

Ran 0 tests containing 0 assertions.
0 failures, 0 errors.

Test results: 0 passes, 0 failures, 0 errors.

Testing poly-rcf.rcf.sqldb.core

Ran 0 tests containing 0 assertions.
0 failures, 0 errors.

Test results: 0 passes, 0 failures, 0 errors.
Running tests for the rcf project using test runner: Polylith built-in clojure.test runner...
Running tests from the rcf project, including 2 bricks: sqldb, rcf

Testing poly-rcf.rcf.test-ns
✅.
Ran 1 tests containing 1 assertions.
0 failures, 0 errors.

Test results: 1 passes, 0 failures, 0 errors.

Testing poly-rcf.rcf.sample2-test
..
Ran 2 tests containing 3 assertions.
0 failures, 0 errors.

Test results: 3 passes, 0 failures, 0 errors.

Testing poly-rcf.rcf.sample-test
✅.
Ran 1 tests containing 1 assertions.
0 failures, 0 errors.

Test results: 1 passes, 0 failures, 0 errors.

Testing poly-rcf.rcf.src-ns
✅.
Ran 1 tests containing 1 assertions.
0 failures, 0 errors.

Test results: 1 passes, 0 failures, 0 errors.

Testing poly-rcf.rcf.config

Ran 0 tests containing 0 assertions.
0 failures, 0 errors.

Test results: 0 passes, 0 failures, 0 errors.

Testing poly-rcf.rcf.sqldb.interface-test
[main] INFO poly-rcf.rcf.sqldb.core - Create component with db {:db-spec {:maximum-pool-size 10, :connection-timeout 30000, :idle-timeout 600000, :validation-timeout 5000, :max-lifetime 1800000, :jdbcUrl jdbc:h2:mem:semmed}}
[main] INFO poly-rcf.rcf.sqldb.interface-test - datasource {:db-spec {:maximum-pool-size 10, :connection-timeout 30000, :idle-timeout 600000, :validation-timeout 5000, :max-lifetime 1800000, :jdbcUrl jdbc:h2:mem:semmed}, :hikari-datasource #object[com.zaxxer.hikari.HikariDataSource 0x497d610c HikariDataSource (null)]}
[main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-2 - Starting...

ERROR in (new-component-test) (DriverDataSource.java:114)
Uncaught exception, not in assertion.
expected: nil
  actual: java.lang.RuntimeException: Failed to get driver instance for jdbcUrl=jdbc:h2:mem:semmed
 at com.zaxxer.hikari.util.DriverDataSource.<init> (DriverDataSource.java:114)
    com.zaxxer.hikari.pool.PoolBase.initializeDataSource (PoolBase.java:326)
    com.zaxxer.hikari.pool.PoolBase.<init> (PoolBase.java:112)
    com.zaxxer.hikari.pool.HikariPool.<init> (HikariPool.java:93)
    com.zaxxer.hikari.HikariDataSource.getConnection (HikariDataSource.java:112)
    next.jdbc.connection$make_connection.invokeStatic (connection.clj:452)
    next.jdbc.connection$make_connection.invoke (connection.clj:436)
    next.jdbc.connection$eval2441$fn__2442.invoke (connection.clj:481)
    next.jdbc.protocols$eval2171$fn__2172$G__2162__2179.invoke (protocols.clj:25)
    next.jdbc$get_connection.invokeStatic (jdbc.clj:168)
    next.jdbc$get_connection.invoke (jdbc.clj:147)
    poly_rcf.rcf.sqldb.interface_test$fn__3426.invokeStatic (interface_test.clj:26)
    poly_rcf.rcf.sqldb.interface_test/fn (interface_test.clj:11)
    clojure.test$test_var$fn__9856.invoke (test.clj:717)
    clojure.test$test_var.invokeStatic (test.clj:717)
    clojure.test$test_var.invoke (test.clj:708)
    clojure.test$test_vars$fn__9882$fn__9887.invoke (test.clj:735)
    clojure.test$default_fixture.invokeStatic (test.clj:687)
    clojure.test$default_fixture.invoke (test.clj:683)
    clojure.test$test_vars$fn__9882.invoke (test.clj:735)
    clojure.test$default_fixture.invokeStatic (test.clj:687)
    clojure.test$default_fixture.invoke (test.clj:683)
    clojure.test$test_vars.invokeStatic (test.clj:731)
    clojure.test$test_all_vars.invokeStatic (test.clj:737)
    clojure.test$test_ns.invokeStatic (test.clj:758)
    clojure.test$test_ns.invoke (test.clj:743)
    clojure.core$map$fn__5935.invoke (core.clj:2772)
    clojure.lang.LazySeq.sval (LazySeq.java:42)
    clojure.lang.LazySeq.seq (LazySeq.java:51)
    clojure.lang.Cons.next (Cons.java:39)
    clojure.lang.RT.boundedLength (RT.java:1790)
    clojure.lang.RestFn.applyTo (RestFn.java:130)
    clojure.core$apply.invokeStatic (core.clj:669)
    clojure.test$run_tests.invokeStatic (test.clj:768)
    clojure.test$run_tests.doInvoke (test.clj:768)
    clojure.lang.RestFn.invoke (RestFn.java:408)
    clojure.core$eval3436.invokeStatic (NO_SOURCE_FILE:0)
    clojure.core$eval3436.invoke (NO_SOURCE_FILE:-1)
    clojure.lang.Compiler.eval (Compiler.java:7194)
    clojure.lang.Compiler.eval (Compiler.java:7184)
    clojure.lang.Compiler.eval (Compiler.java:7149)
    clojure.core$eval.invokeStatic (core.clj:3215)
    clojure.core$eval.invoke (core.clj:3211)
    clojure.core$eval615.invokeStatic (NO_SOURCE_FILE:0)
    clojure.core$eval615.invoke (NO_SOURCE_FILE:-1)
    clojure.lang.Compiler.eval (Compiler.java:7194)
    clojure.lang.Compiler.eval (Compiler.java:7149)
    jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (NativeMethodAccessorImpl.java:-2)
    jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
    jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke (Method.java:568)
    polylith.clj.core.common.class_loader$invoke_in_STAR_.invokeStatic (class_loader.clj:31)
    polylith.clj.core.common.class_loader$invoke_in_STAR_.doInvoke (class_loader.clj:27)
    clojure.lang.RestFn.invoke (RestFn.java:494)
    polylith.clj.core.common.class_loader$eval_in_STAR_$print_read_eval__3804.invoke (class_loader.clj:49)
    polylith.clj.core.common.class_loader$eval_in_STAR_.invokeStatic (class_loader.clj:51)
    polylith.clj.core.common.class_loader$eval_in_STAR_.invoke (class_loader.clj:45)
    polylith.clj.core.common.class_loader$eval_in.invokeStatic (class_loader.clj:61)
    polylith.clj.core.common.class_loader$eval_in.invoke (class_loader.clj:60)
    polylith.clj.core.common.interface$eval_in.invokeStatic (interface.clj:22)
    polylith.clj.core.common.interface$eval_in.invoke (interface.clj:21)
    polylith.clj.core.test_runner_orchestrator.core$__GT_eval_in_project$fn__10967.invoke (core.clj:108)
    polylith.clj.core.clojure_test_test_runner.core$run_test_statements$fn__45019.invoke (core.clj:59)
    polylith.clj.core.clojure_test_test_runner.core$run_test_statements.invokeStatic (core.clj:58)
    polylith.clj.core.clojure_test_test_runner.core$run_test_statements.invoke (core.clj:52)
    polylith.clj.core.clojure_test_test_runner.core$create$reify__45046.run_tests (core.clj:98)
    polylith.clj.core.test_runner_orchestrator.core$run_tests_for_project_with_test_runner.invokeStatic (core.clj:88)
    polylith.clj.core.test_runner_orchestrator.core$run_tests_for_project_with_test_runner.invoke (core.clj:77)
    polylith.clj.core.test_runner_orchestrator.core$run_tests_for_project.invokeStatic (core.clj:159)
    polylith.clj.core.test_runner_orchestrator.core$run_tests_for_project.invoke (core.clj:129)
    polylith.clj.core.test_runner_orchestrator.core$run.invokeStatic (core.clj:214)
    polylith.clj.core.test_runner_orchestrator.core$run.invoke (core.clj:197)
    polylith.clj.core.test_runner_orchestrator.interface$run.invokeStatic (interface.clj:5)
    polylith.clj.core.test_runner_orchestrator.interface$run.invoke (interface.clj:4)
    polylith.clj.core.command.test$run.invokeStatic (test.clj:11)
    polylith.clj.core.command.test$run.invoke (test.clj:5)
    polylith.clj.core.command.core$execute.invokeStatic (core.clj:95)
    polylith.clj.core.command.core$execute.invoke (core.clj:70)
    polylith.clj.core.command.interface$execute_command.invokeStatic (interface.clj:5)
    polylith.clj.core.command.interface$execute_command.invoke (interface.clj:4)
    polylith.clj.core.poly_cli.core$_main.invokeStatic (core.clj:33)
    polylith.clj.core.poly_cli.core$_main.doInvoke (core.clj:7)
    clojure.lang.RestFn.applyTo (RestFn.java:137)
    clojure.lang.Var.applyTo (Var.java:705)
    clojure.core$apply.invokeStatic (core.clj:667)
    clojure.main$main_opt.invokeStatic (main.clj:514)
    clojure.main$main_opt.invoke (main.clj:510)
    clojure.main$main.invokeStatic (main.clj:664)
    clojure.main$main.doInvoke (main.clj:616)
    clojure.lang.RestFn.applyTo (RestFn.java:137)
    clojure.lang.Var.applyTo (Var.java:705)
    clojure.main.main (main.java:40)
Caused by: java.sql.SQLException: No suitable driver
 at java.sql.DriverManager.getDriver (DriverManager.java:299)
    com.zaxxer.hikari.util.DriverDataSource.<init> (DriverDataSource.java:106)
    com.zaxxer.hikari.pool.PoolBase.initializeDataSource (PoolBase.java:326)
    com.zaxxer.hikari.pool.PoolBase.<init> (PoolBase.java:112)
    com.zaxxer.hikari.pool.HikariPool.<init> (HikariPool.java:93)
    com.zaxxer.hikari.HikariDataSource.getConnection (HikariDataSource.java:112)
    next.jdbc.connection$make_connection.invokeStatic (connection.clj:452)
    next.jdbc.connection$make_connection.invoke (connection.clj:436)
    next.jdbc.connection$eval2441$fn__2442.invoke (connection.clj:481)
    next.jdbc.protocols$eval2171$fn__2172$G__2162__2179.invoke (protocols.clj:25)
    next.jdbc$get_connection.invokeStatic (jdbc.clj:168)
    next.jdbc$get_connection.invoke (jdbc.clj:147)
    poly_rcf.rcf.sqldb.interface_test$fn__3426.invokeStatic (interface_test.clj:26)
    poly_rcf.rcf.sqldb.interface_test/fn (interface_test.clj:11)
    clojure.test$test_var$fn__9856.invoke (test.clj:717)
    clojure.test$test_var.invokeStatic (test.clj:717)
    clojure.test$test_var.invoke (test.clj:708)
    clojure.test$test_vars$fn__9882$fn__9887.invoke (test.clj:735)
    clojure.test$default_fixture.invokeStatic (test.clj:687)
    clojure.test$default_fixture.invoke (test.clj:683)
    clojure.test$test_vars$fn__9882.invoke (test.clj:735)
    clojure.test$default_fixture.invokeStatic (test.clj:687)
    clojure.test$default_fixture.invoke (test.clj:683)
    clojure.test$test_vars.invokeStatic (test.clj:731)
    clojure.test$test_all_vars.invokeStatic (test.clj:737)
    clojure.test$test_ns.invokeStatic (test.clj:758)
    clojure.test$test_ns.invoke (test.clj:743)
    clojure.core$map$fn__5935.invoke (core.clj:2772)
    clojure.lang.LazySeq.sval (LazySeq.java:42)
    clojure.lang.LazySeq.seq (LazySeq.java:51)
    clojure.lang.Cons.next (Cons.java:39)
    clojure.lang.RT.boundedLength (RT.java:1790)
    clojure.lang.RestFn.applyTo (RestFn.java:130)
    clojure.core$apply.invokeStatic (core.clj:669)
    clojure.test$run_tests.invokeStatic (test.clj:768)
    clojure.test$run_tests.doInvoke (test.clj:768)
    clojure.lang.RestFn.invoke (RestFn.java:408)
    clojure.core$eval3436.invokeStatic (NO_SOURCE_FILE:0)
    clojure.core$eval3436.invoke (NO_SOURCE_FILE:-1)
    clojure.lang.Compiler.eval (Compiler.java:7194)
    clojure.lang.Compiler.eval (Compiler.java:7184)
    clojure.lang.Compiler.eval (Compiler.java:7149)
    clojure.core$eval.invokeStatic (core.clj:3215)
    clojure.core$eval.invoke (core.clj:3211)
    clojure.core$eval615.invokeStatic (NO_SOURCE_FILE:0)
    clojure.core$eval615.invoke (NO_SOURCE_FILE:-1)
    clojure.lang.Compiler.eval (Compiler.java:7194)
    clojure.lang.Compiler.eval (Compiler.java:7149)
    jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (NativeMethodAccessorImpl.java:-2)
    jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
    jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke (Method.java:568)
    polylith.clj.core.common.class_loader$invoke_in_STAR_.invokeStatic (class_loader.clj:31)
    polylith.clj.core.common.class_loader$invoke_in_STAR_.doInvoke (class_loader.clj:27)
    clojure.lang.RestFn.invoke (RestFn.java:494)
    polylith.clj.core.common.class_loader$eval_in_STAR_$print_read_eval__3804.invoke (class_loader.clj:49)
    polylith.clj.core.common.class_loader$eval_in_STAR_.invokeStatic (class_loader.clj:51)
    polylith.clj.core.common.class_loader$eval_in_STAR_.invoke (class_loader.clj:45)
    polylith.clj.core.common.class_loader$eval_in.invokeStatic (class_loader.clj:61)
    polylith.clj.core.common.class_loader$eval_in.invoke (class_loader.clj:60)
    polylith.clj.core.common.interface$eval_in.invokeStatic (interface.clj:22)
    polylith.clj.core.common.interface$eval_in.invoke (interface.clj:21)
    polylith.clj.core.test_runner_orchestrator.core$__GT_eval_in_project$fn__10967.invoke (core.clj:108)
    polylith.clj.core.clojure_test_test_runner.core$run_test_statements$fn__45019.invoke (core.clj:59)
    polylith.clj.core.clojure_test_test_runner.core$run_test_statements.invokeStatic (core.clj:58)
    polylith.clj.core.clojure_test_test_runner.core$run_test_statements.invoke (core.clj:52)
    polylith.clj.core.clojure_test_test_runner.core$create$reify__45046.run_tests (core.clj:98)
    polylith.clj.core.test_runner_orchestrator.core$run_tests_for_project_with_test_runner.invokeStatic (core.clj:88)
    polylith.clj.core.test_runner_orchestrator.core$run_tests_for_project_with_test_runner.invoke (core.clj:77)
    polylith.clj.core.test_runner_orchestrator.core$run_tests_for_project.invokeStatic (core.clj:159)
    polylith.clj.core.test_runner_orchestrator.core$run_tests_for_project.invoke (core.clj:129)
    polylith.clj.core.test_runner_orchestrator.core$run.invokeStatic (core.clj:214)
    polylith.clj.core.test_runner_orchestrator.core$run.invoke (core.clj:197)
    polylith.clj.core.test_runner_orchestrator.interface$run.invokeStatic (interface.clj:5)
    polylith.clj.core.test_runner_orchestrator.interface$run.invoke (interface.clj:4)
    polylith.clj.core.command.test$run.invokeStatic (test.clj:11)
    polylith.clj.core.command.test$run.invoke (test.clj:5)
    polylith.clj.core.command.core$execute.invokeStatic (core.clj:95)
    polylith.clj.core.command.core$execute.invoke (core.clj:70)
    polylith.clj.core.command.interface$execute_command.invokeStatic (interface.clj:5)
    polylith.clj.core.command.interface$execute_command.invoke (interface.clj:4)
    polylith.clj.core.poly_cli.core$_main.invokeStatic (core.clj:33)
    polylith.clj.core.poly_cli.core$_main.doInvoke (core.clj:7)
    clojure.lang.RestFn.applyTo (RestFn.java:137)
    clojure.lang.Var.applyTo (Var.java:705)
    clojure.core$apply.invokeStatic (core.clj:667)
    clojure.main$main_opt.invokeStatic (main.clj:514)
    clojure.main$main_opt.invoke (main.clj:510)
    clojure.main$main.invokeStatic (main.clj:664)
    clojure.main$main.doInvoke (main.clj:616)
    clojure.lang.RestFn.applyTo (RestFn.java:137)
    clojure.lang.Var.applyTo (Var.java:705)
    clojure.main.main (main.java:40)
.
Ran 1 tests containing 1 assertions.
0 failures, 1 errors.

Test results: 0 passes, 0 failures, 1 errors.

@ieugen ieugen self-assigned this May 8, 2023
@ieugen ieugen changed the title Poly 261 Poly 261 - Classpath stability for tests May 8, 2023
@ieugen ieugen merged commit 49b63d0 into main May 8, 2023
@ieugen ieugen deleted the poly-261 branch May 8, 2023 14:52
@tengstrand
Copy link

tengstrand commented May 18, 2023

Hi @ieugen!

Sorry for late reply.

Yes, I can reproduce this error. @seancorfield said that he will have a look at this (he knows these stuff better than me!).

The reason why the test runner runs the tests for a brick in all the projects, is that each project can potentially be configured differently, e.g. by using different library version, or different brick for an interface.

The Polylith codebase itself doesn't have these differences between projects, and all tests are therefore only executed in the poly project. The tests for the api project are disabled by adding :test [] or :test {:include []}}, see:
https://github.com/polyfy/polylith/blob/928e9ddce6c08889ce36e6b8367b57a6993295c6/workspace.edn#L10

You can follow the same pattern if you only want to run the brick tests in one project.

@seancorfield
Copy link

Yeah, it's a tricky one because really what Polylith should do is use tools.deps directly for dependency resolution because a) that has a predictable algorithm and b) it would be weird for clojure CLI and poly to produce different a classpath when running tests.

Unfortunately, it's also very tricky to arrange given the way poly currently handles deps.edn files and what the tools.deps API provides. I'm still thinking about the best way to make this work (but it's going to be fairly extensive changes to poly to handle dependencies "properly")....

@ieugen
Copy link
Owner Author

ieugen commented May 19, 2023

Thanks @tengstrand and @seancorfield for looking at this !

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

Successfully merging this pull request may close these issues.

3 participants