test: assert that pre-migrations are actually run

This commit is contained in:
Steven Allen 2021-01-27 16:12:08 -08:00
parent 39d4f6780d
commit 4890d83acb

View File

@ -357,6 +357,8 @@ func TestForkPreMigration(t *testing.T) {
require.False(t, found) require.False(t, found)
} }
counter := make(chan struct{}, 10)
sm, err := NewStateManagerWithUpgradeSchedule( sm, err := NewStateManagerWithUpgradeSchedule(
cg.ChainStore(), UpgradeSchedule{{ cg.ChainStore(), UpgradeSchedule{{
Network: 1, Network: 1,
@ -374,6 +376,8 @@ func TestForkPreMigration(t *testing.T) {
// the cache should be setup correctly. // the cache should be setup correctly.
checkCache(t, cache) checkCache(t, cache)
counter <- struct{}{}
return root, nil return root, nil
}, },
PreMigrations: []PreMigration{{ PreMigrations: []PreMigration{{
@ -386,6 +390,8 @@ func TestForkPreMigration(t *testing.T) {
err := cache.Write("foo", fooCid) err := cache.Write("foo", fooCid)
require.NoError(t, err) require.NoError(t, err)
counter <- struct{}{}
return nil return nil
}, },
}, { }, {
@ -398,6 +404,8 @@ func TestForkPreMigration(t *testing.T) {
err := cache.Write("bar", barCid) err := cache.Write("bar", barCid)
require.NoError(t, err) require.NoError(t, err)
counter <- struct{}{}
return nil return nil
}, },
}, { }, {
@ -410,6 +418,8 @@ func TestForkPreMigration(t *testing.T) {
err := cache.Write("fail", failCid) err := cache.Write("fail", failCid)
require.NoError(t, err) require.NoError(t, err)
counter <- struct{}{}
// Fail this migration. The cached entry should not be persisted. // Fail this migration. The cached entry should not be persisted.
return fmt.Errorf("failed") return fmt.Errorf("failed")
}, },
@ -422,6 +432,8 @@ func TestForkPreMigration(t *testing.T) {
<-ctx.Done() <-ctx.Done()
close(wasCanceled) close(wasCanceled)
counter <- struct{}{}
return nil return nil
}, },
}, { }, {
@ -431,6 +443,8 @@ func TestForkPreMigration(t *testing.T) {
checkCache(t, cache) checkCache(t, cache)
counter <- struct{}{}
return nil return nil
}, },
}}}, }}},
@ -463,4 +477,7 @@ func TestForkPreMigration(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
} }
// We have 5 pre-migration steps, and the migration. They should all have written something
// to this channel.
require.Equal(t, 6, len(counter))
} }