command: Fix TestMetaBackend_configureNewWithState

This test was initially failing because its fixture had a state which our
new state models consider to be "empty", and thus it was not migrated.

After fixing that (by adding an output to the fixture), this revealed a
bug that the lineage was not being persisted through the migration. This
is fixed by using the statemgr.Migrate method instead of writing via the
normal Writer interface, which allows two cooperating state managers to
properly transfer the lineage and serial along with the state snapshot.
This commit is contained in:
Martin Atkins 2018-11-12 18:30:01 -08:00
parent 24046ab833
commit aacbe1d14b
3 changed files with 15 additions and 9 deletions

View File

@ -382,8 +382,10 @@ func (m *Meta) backendMigrateState_s_s(opts *backendMigrateOpts) error {
} }
} }
// Confirmed! Write. // Confirmed! We'll have the statemgr package handle the migration, which
if err := stateTwo.WriteState(one); err != nil { // includes preserving any lineage/serial information where possible, if
// both managers support such metadata.
if err := statemgr.Migrate(stateTwo, stateOne); err != nil {
return fmt.Errorf(strings.TrimSpace(errBackendStateCopy), return fmt.Errorf(strings.TrimSpace(errBackendStateCopy),
opts.OneType, opts.TwoType, err) opts.OneType, opts.TwoType, err)
} }

View File

@ -326,24 +326,23 @@ func TestMetaBackend_configureNewWithState(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("unexpected error: %s", err) t.Fatalf("unexpected error: %s", err)
} }
if err := s.RefreshState(); err != nil { state, err := statemgr.RefreshAndRead(s)
if err != nil {
t.Fatalf("unexpected error: %s", err) t.Fatalf("unexpected error: %s", err)
} }
state := s.State()
if state == nil { if state == nil {
t.Fatal("state is nil") t.Fatal("state is nil")
} }
if testStateMgrCurrentLineage(s) != "backend-new-migrate" { if got, want := testStateMgrCurrentLineage(s), "backend-new-migrate"; got != want {
t.Fatalf("bad: %#v", state) t.Fatalf("lineage changed during migration\nnow: %s\nwas: %s", got, want)
} }
// Write some state // Write some state
state = states.NewState() state = states.NewState()
mark := markStateForMatching(state, "changing") mark := markStateForMatching(state, "changing")
s.WriteState(state) if err := statemgr.WriteAndPersist(s, state); err != nil {
if err := s.PersistState(); err != nil {
t.Fatalf("unexpected error: %s", err) t.Fatalf("unexpected error: %s", err)
} }

View File

@ -8,7 +8,12 @@
"path": [ "path": [
"root" "root"
], ],
"outputs": {}, "outputs": {
"foo": {
"type": "string",
"value": "bar"
}
},
"resources": {}, "resources": {},
"depends_on": [] "depends_on": []
} }