Fix flaky tests (bug 1008457)

- Sort lists of ids for consistent test behaviour