Wait for data to be inserted

Fixes #3057.