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

Appending expecting revision 0 does not return an error #69

Closed
fabriziosestito opened this issue Jun 2, 2022 · 4 comments · Fixed by #70
Closed

Appending expecting revision 0 does not return an error #69

fabriziosestito opened this issue Jun 2, 2022 · 4 comments · Fixed by #70

Comments

@fabriziosestito
Copy link
Contributor

fabriziosestito commented Jun 2, 2022

I am trying to integrate spear with commanded by strangling the Extreme library from the extreme_adapter.

Appending works, but I realized some test was not passing due to the expect: 0 being ignored.
The test tries to append 3 events and then it asserts that appending expecting a revision: 0 returns an error.
Other assertions are true with revisions >= 1

Here is the test for reference:

      test "should fail to append to a stream because of wrong expected version", %{
        event_store: event_store,
        event_store_meta: event_store_meta
      } do
        assert :ok == event_store.append_to_stream(event_store_meta, "stream", 0, build_events(3))

        assert {:error, :wrong_expected_version} ==
                 event_store.append_to_stream(event_store_meta, "stream", 0, build_events(1))

        assert {:error, :wrong_expected_version} ==
                 event_store.append_to_stream(event_store_meta, "stream", 1, build_events(1))

        assert {:error, :wrong_expected_version} ==
                 event_store.append_to_stream(event_store_meta, "stream", 2, build_events(1))

        assert :ok == event_store.append_to_stream(event_store_meta, "stream", 3, build_events(1))
      end

where:

  defp expected_version(:any_version), do: :any
  defp expected_version(:no_stream), do: :empty
  defp expected_version(:stream_exists), do: :exists
  defp expected_version(0), do: :empty

This line seems to be the culprit:

defp map_expectation(revision) when is_integer(revision) and revision >= 1,

Removing the guard seems to do the trick.

Is there any reason why the revision needs to be >= 1 while mapping the expectations?

Thanks in advance!

@the-mikedavis
Copy link
Collaborator

I am trying to integrate spear with commanded

Sweet! Thanks for working on that 😀

Is there any reason why the revision needs to be >= 1 while mapping the expectations?

I was probably thinking at the time that if you wanted to expect 0 you could use :empty but I don't see a problem with expecting 0 now that you mention it. Would you like to submit a PR to change that guard? I think having it be revision >= 0 would be my preference rather than just removing it - that field in the protobuf definitions is an unsigned int so I would like to protect against negative values /~https://github.com/EventStore/EventStore/blob/2604dea053a394864d94acdd48d90929cac30601/src/Protos/Grpc/streams.proto#L144

@fabriziosestito
Copy link
Contributor Author

@the-mikedavis thanks for the fast answer, I baked a small PR as you suggested.
I see the same guard being used for the batch append requests: /~https://github.com/fabriziosestito/spear/blob/85c0d6e9319c2e1b9caa8fd8c4c9d5a42971fa91/lib/spear/writing.ex#L138

Should we change this one as well?

@the-mikedavis
Copy link
Collaborator

Oh yeah let's allow 0 there as well 👍

@fabriziosestito
Copy link
Contributor Author

@the-mikedavis force-pushed, done!

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 a pull request may close this issue.

2 participants