Wait for data to be inserted

Fixes #3057.
Merge pull request #1400 from djmitche/bug3057

Wait for data to be inserted