Added SELECT FOR UPDATE to prevent deadlocks in tests

Closes-Bug: #1308115

Change-Id: Ib72bb7a054a13c6fadfa548bfc4640b198c47cfe
Merge "Added SELECT FOR UPDATE to prevent deadlocks in tests"