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

set_count_on_hand should use lock just like adjust_count_on_hand #1101

Closed

Conversation

jrochkind
Copy link
Contributor

No idea how to write a test for this. But if adjust_count_on_hand, right
above this method, needs a db lock to avoid race conditions -- then surely
set_count_on_hand does too, no?

Or if neither does, that's a different PR.

@jrochkind
Copy link
Contributor Author

Or perhaps adjust_count_on_hand should actually be written in terms of set_count_on_hand?

@jrochkind
Copy link
Contributor Author

Here's the failure from circleci:


  1) Spree::StockItem#after_save inventory_cache_threshold is set count on hand stays above threshold
     Failure/Error:
       expect do
         subject.set_count_on_hand(8)
       end.not_to change { subject.variant.updated_at }

       expected result not to have changed, but did change from 2016-04-24 20:20:41.258599812 +0000 to 2016-04-24 20:20:41.258599000 +0000
     # ./spec/models/spree/stock_item_spec.rb:223:in `block (4 levels) in <top (required)>'

Huh? Anyone have an idea what's going on? How does no change but adding a db lock to guard against race conditions result in a variant getting it's updated_at touched when it wasn't before?

Any ideas?

@peterberkenbosch
Copy link
Contributor

not sure either how you could explicitly test this, I think this change should just keep the existing specs green. I cherry-picked your commit in a local branch based of master and the specs are green now. Will submit a new PR with your commit in a sec.

@jrochkind
Copy link
Contributor Author

Thanks so much @peterberkenbosch !

@tvdeyen
Copy link
Member

tvdeyen commented Jun 13, 2017

Closing as stale. Please reopen if you think this is still something we should to tackle.

@tvdeyen tvdeyen closed this Jun 13, 2017
@bbuchalter
Copy link
Contributor

I think this is an important change that we need to continue working at, but I don't know how to move this forward.

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 this pull request may close these issues.

4 participants