Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions integration_test/myxql/storage_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ defmodule Ecto.Integration.StorageTest do
drop_database()
end

test "structure load will fail on SQL errors" do
create_database()
File.mkdir_p!(tmp_path())
error_path = Path.join(tmp_path(), "error.sql")
File.write!(error_path, "SELECT 1; SELECKT 1; SELECT 2;")

{:error, message} =
Ecto.Adapters.MyXQL.structure_load(tmp_path(), [dump_path: error_path] ++ params())

assert message =~ ~r/ERROR.*SELECKT/
after
drop_database()
end

test "storage status is up when database is created" do
create_database()
assert :up == Ecto.Adapters.MyXQL.storage_status(params())
Expand Down
5 changes: 5 additions & 0 deletions lib/ecto/adapters/myxql.ex
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,8 @@ defmodule Ecto.Adapters.MyXQL do
args: args
]

# Trap exits in case mysql dies in the middle of execution so that we can surface the error
Process.flag(:trap_exit, true)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to trap exits? I am not sure if ports in Erlang are linked to the current process. But if we do have, we should probably revert the trap_exit flag to its original value once we are done!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe so but definitely not an expert. I originally got it from the erlang docs example here: https://www.erlang.org/doc/system/c_port.html.

I also did a test here where I ignore the "normal" exist message and also don't trap exits and I didn't receive the abnormal exit message.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably revert the trap_exit flag to its original value once we are done!

done!

port = Port.open({:spawn_executable, abs_cmd}, port_opts)
Port.command(port, contents)
# Use this as a signal to close the port since we cannot
Expand Down Expand Up @@ -653,6 +655,9 @@ defmodule Ecto.Adapters.MyXQL do
collect_output(port, acc)
end

{:EXIT, ^port, _reason} ->
{acc, 1}

{^port, {:exit_status, status}} ->
{acc, status}
end
Expand Down
Loading