tests: Remove races from test_metadata_dump

The test suffered from a set of races when waiting for metadata to be dumped,
eg. some entries were added to changelog.0.mfs after reading version number
of the last entry. This commit modifies the test to wait for the dump to be
finished in a way that should always work and removes the race. Also some
refactoring has been made to avoid code duplication in the test.

Change-Id: I5dc2d9d62a8776c0eb6ff21a14f71285d9720195