Astarte Import: Fix astarte import test#1069
Astarte Import: Fix astarte import test#1069osmanhadzic wants to merge 1 commit intoastarte-platform:masterfrom
Conversation
| children = [ | ||
| {Astarte.DataAccess, xandra_options: Astarte.DataAccess.Config.xandra_options!()} | ||
| ] |
There was a problem hiding this comment.
It would be better to use a different Xandra pool just for tests, so that we're not using DataAccess' resource.
| children = [ | |
| {Astarte.DataAccess, xandra_options: Astarte.DataAccess.Config.xandra_options!()} | |
| ] | |
| xandra_options = | |
| Astarte.DataAccess.Config.xandra_options!() | |
| |> Keyword.put(:name, :test_xandra) | |
| children = [ | |
| {Xandra.Cluster, xandra_options} | |
| ] |
This would mean that all calls to Xandra.Cluster functions should use the new pool, see comment above for an example
| end) | ||
|
|
||
| on_exit(fn -> | ||
| Xandra.Cluster.run(:astarte_data_access_xandra, fn conn -> |
There was a problem hiding this comment.
| Xandra.Cluster.run(:astarte_data_access_xandra, fn conn -> | |
| Xandra.Cluster.run(:test_xandra, fn conn -> |
| setup do | ||
| Xandra.Cluster.run(:astarte_data_access_xandra, fn conn -> | ||
| DatabaseTestHelper.seed_data(conn) | ||
| end) | ||
| end |
There was a problem hiding this comment.
Usually setup blocks are below setup_alls, as setup_all runs before all tests in a case and setup runs before each test in a case. See https://hexdocs.pm/ex_unit/ExUnit.Callbacks.html#setup_all/2
| {Astarte.DataAccess, xandra_options: Astarte.DataAccess.Config.xandra_options!()} | ||
| ] | ||
|
|
||
| Supervisor.start_link(children, strategy: :one_for_one) |
There was a problem hiding this comment.
Consider whether this could be changed to a start_supervised call inside a setup_all block (see https://hexdocs.pm/ex_unit/ExUnit.Callbacks.html#start_supervised/2)
There was a problem hiding this comment.
Sorry, I tried to implement your suggestion, but in this case, it doesn’t work. I think this PR can resolve my problem with database connections. #1061
| Xandra.execute(conn, @drop_keyspace, [], []) | ||
| :timer.sleep(3000) | ||
|
|
||
| Xandra.execute(conn, @delete_realm_from_astarte_realms, [], []) | ||
| :timer.sleep(3000) |
There was a problem hiding this comment.
Are sleep really needed here?
There was a problem hiding this comment.
You are right, I removed sleep from the code.
Implement a database test helper for use in `populatedb_test`. to test import xml file into the database. Edit test xml file to be identical like expected xml file in `astarte_export`. Add `database_test_helper.exs` to help with setting up the database for tests. Signed-off-by: Osman Hadzic <osman.hadzic@secomind.com>
4620071 to
6d4a9d7
Compare
What this PR does / why we need it:
Sets up an Astarte realm instance pre-populated with data (devices, interfaces, endpoints) to facilitate testing for data imports.
Drops the database after testing to maintain a clean environment.
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g. usage docs, diagrams, etc.: