the following test is failing from time to time:
test "successful message creation" do
room = Room.changeset(@valid_room_attrs, :create) |> Repo.insert!
msg0 = Message.changeset(%Message{}, @valid_message_attrs) |> put_assoc(:room, room) |> Repo.insert!
msg1 = Message.changeset(%Message{}, @valid_message_attrs) |> put_assoc(:room, room) |> Repo.insert!
room_uuid = room.uuid
messages = (from msg in Message, where: msg.room_uuid == ^room.uuid, select: msg, preload: :room) |> Repo.all
all_messages = (from msg in Message, select: msg, preload: :room) |> Repo.all
assert 2 == Enum.count(all_messages)
assert 2 == Enum.count(messages)
end
it does not fail all the time but when it does it fails like this:
1) test successful message creation (ChatApi.ModelTest)
test/models/model_test.exs:38
Assertion with == failed
code: 2 == Enum.count(messages)
lhs: 2
rhs: 0
stacktrace:
test/models/model_test.exs:53: (test)
here is the model for Room:
@primary_key {:uuid, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "room" do
field :name, :string
field :topic, :string
field :description, :string
field :status, :string
timestamps()
end
and here is the model for message:
@primary_key {:uuid, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "message" do
field :content, :map
belongs_to :room, Room, foreign_key: :room_uuid, references: :uuid
timestamps()
end
I use Ecto version is 2.1.4 and mariaex 0.8.2 (mysql 5.7.18). Does anyone know what might be happening?
Just switched to normal bigint auto-incremented IDs and all works fine. Something is off with UUIDs, it would be great to know if I am doing something wrong or if UUIDs are flakey yet?