vvvvalvalval / datomock

Mocking and forking Datomic Peer connections in-memory.
MIT License
130 stars 6 forks source link

Use agent instead of atom to implement mock connection #4

Closed ChrisBlom closed 6 years ago

ChrisBlom commented 6 years ago

Uses an agent to manage the state of the mock connection, see https://github.com/vvvvalvalval/datomock/issues/2

vvvvalvalval commented 6 years ago

Can't merge this right now because it may leave some concurrency issues unaddressed. In particular, the proposed change does not let you read your own writes with (datomic.api/db conn), and I'm not sure that's okay (stay tuned to this StackOverflow question).

Even if it is okay, the need for a proper implementation of sync will probably become more necessary.

I'll keep you posted as I make progress.

ChrisBlom commented 6 years ago

According to the docs transact returns a completed future, so that would suggest that after (d/transact conn data) finished, the data is transacted, and your writes should be in (d/db conn) , but it would be good if someone from Datomic can confirm this.

I see now that my implementation is not correct, i've implemened transact-async not transact, i'll fix this. I this the concurrency issue you mean?

ChrisBlom commented 6 years ago

I noticed another problem: the future is delivered before the fn that updates the agent returns, so potentially the agent state is not updated yet once the future is delivered, do you now a clean way to solve this?

vvvvalvalval commented 6 years ago

I noticed another problem: the future is delivered before the fn that updates the agent returns, so potentially the agent state is not updated yet once the future is delivered, do you now a clean way to solve this?

@ChrisBlom it is not another problem, it is the same problem :) I had not noticed the issue with transact's implementation.

vvvvalvalval commented 6 years ago

@ChrisBlom thanks, I'd appreciate if you could add a little test for the RYW semantics

vvvvalvalval commented 6 years ago

And we still need a proper implementation of (d/sync conn t), if you want to give it a shot the best strategy I can think of is adding a watch for to the agent that looks up the basis-t (then self-removes)

ChrisBlom commented 6 years ago

I've implemented (d/sync conn t) and added a test for d/transact-async

ChrisBlom commented 6 years ago

the implementation is not correct, (d/sync conn t) does not work when the db already has t, please ignore for now