electric-sql / legacy-cli

ElectricSQL command line interface (CLI) tool.
https://electric-sql.com/docs
Apache License 2.0
10 stars 0 forks source link

Two unit tests fail on Fedora 37 #37

Open alco opened 1 year ago

alco commented 1 year ago
$ mix test
==> electric_migrations
*****.....****...................
Finished in 0.1 seconds (0.09s async, 0.04s sync)
33 tests, 0 failures, 9 skipped

Randomized with seed 789701
==> electric_cli
.........................................

  1) test electric migrations revert --all revert all (ElectricCli.Commands.MigrationsTest)
     apps/electric_cli/test/electric_cli/commands/migrations_test.exs:297
     match (=) failed
     code:  assert {{:ok, output}, _} = run_cmd(args)
     left:  {{:ok, output}, _}
     right: {{:error, "\e[31m\e[1mERROR: \e[0m\e[37mexdev\e[0m"}, "\e[2K\r⠋ Reverting all migrations … \e[2K\r\e[2K\rReverting all migrations failed.\n"}
     stacktrace:
       test/electric_cli/commands/migrations_test.exs:302: (test)

.........................................

  2) test electric init --sync-down syncs down server migrations (ElectricCli.Commands.InitTest)
     apps/electric_cli/test/electric_cli/commands/init_test.exs:206
     match (=) failed
     code:  assert {{:ok, output}, _} = run_cmd(args)
     left:  {{:ok, output}, _}
     right: {{:error, "\e[31m\e[1mERROR: \e[0m\e[37mfailed to save config file\e[0m"}, ""}
     stacktrace:
       test/electric_cli/commands/init_test.exs:211: (test)

......................................................................
Finished in 2.7 seconds (0.00s async, 2.7s sync)
154 tests, 2 failures

Randomized with seed 789701

Looking into second test failure, I learned that it's caused by the {:error, :exdev} being returned from the init_migrations() function in https://github.com/electric-sql/cli/blob/1147ea802332c71a747b304f8b2533a6bd4e9f2f/apps/electric_cli/lib/electric_cli/commands/init.ex#L134-L139

I added a call to IO.inspect on line 134 and got this output:

{:ok,
 %ElectricCli.Config{
   app: "sync-from-1234",
   debug: false,
   defaultEnv: "default",
   directories: %ElectricCli.Config.Directories{
     migrations: "/home/alco/code/electric-sql/cli/apps/electric_cli/tmp/ElectricCli.Commands.InitTest/test-electric-init---sync-down-syncs-down-server-migrations-444bfd83/some-other-folder/migrations",
     output: "/home/alco/code/electric-sql/cli/apps/electric_cli/tmp/ElectricCli.Commands.InitTest/test-electric-init---sync-down-syncs-down-server-migrations-444bfd83/some-other-folder/.electric"
   },
   environments: %{
     default: %ElectricCli.Config.Environment{
       console: nil,
       replication: nil,
       slug: "default"
     }
   },
   root: "/home/alco/code/electric-sql/cli/apps/electric_cli/tmp/ElectricCli.Commands.InitTest/test-electric-init---sync-down-syncs-down-server-migrations-444bfd83/some-other-folder"
 }}

The exdev error is Linux's way of saying that a file cannot be renamed between different file systems (or mount points). I do have the /tmp mounted as tmpfs:

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        4.0M     0  4.0M   0% /dev
tmpfs           7.7G  6.7M  7.7G   1% /dev/shm
tmpfs           3.1G  2.0M  3.1G   1% /run
/dev/dm-0       237G   74G  163G  32% /
tmpfs           7.7G  2.9M  7.7G   1% /tmp
/dev/dm-0       237G   74G  163G  32% /home
/dev/nvme0n1p2  974M  288M  619M  32% /boot
/dev/nvme0n1p1  599M   28M  572M   5% /boot/efi
tmpfs           1.6G  260K  1.6G   1% /run/user/1000

So the problem probably stems from the fact that ExUnit generates tmp dirs inside the Elixir app's directory while the ElectricCli.Migrations.sync_down_migrations() function creates its own tmp dir using System.tmp_dir().

More info about my system:

$ uname -a
Linux fedora 6.2.9-200.fc37.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Mar 30 22:31:57 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

$ iex
Erlang/OTP 25 [erts-13.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit:ns]

Interactive Elixir (1.14.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> System.tmp_dir()
"/tmp"