diff options
author | Tonis Tiigi <tonistiigi@gmail.com> | 2016-02-05 17:04:44 -0800 |
---|---|---|
committer | Tonis Tiigi <tonistiigi@gmail.com> | 2016-02-05 17:05:19 -0800 |
commit | 4852932494b6e13b669937c0e27f0434513f5ad5 (patch) | |
tree | fdb6e5f5337c1d27a158e067bbb581cceceb6d5b /image/store_test.go | |
parent | b3bacb42afeb66f7de594ef5b0433a23697f6753 (diff) | |
download | docker-4852932494b6e13b669937c0e27f0434513f5ad5.tar.gz |
Clear old parent reference on resetting image parent
On migration 2 different images can end up with same
content addressable ID, meaning `SetParent` will be called
multiple times. Previous version did not clear the old
in-memory reference.
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Diffstat (limited to 'image/store_test.go')
-rw-r--r-- | image/store_test.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/image/store_test.go b/image/store_test.go index 279708fcba..50f8aa8b84 100644 --- a/image/store_test.go +++ b/image/store_test.go @@ -233,6 +233,62 @@ func TestSearchAfterDelete(t *testing.T) { } } +func TestParentReset(t *testing.T) { + tmpdir, err := ioutil.TempDir("", "images-fs-store") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(tmpdir) + fs, err := NewFSStoreBackend(tmpdir) + if err != nil { + t.Fatal(err) + } + + is, err := NewImageStore(fs, &mockLayerGetReleaser{}) + if err != nil { + t.Fatal(err) + } + + id, err := is.Create([]byte(`{"comment": "abc1", "rootfs": {"type": "layers"}}`)) + if err != nil { + t.Fatal(err) + } + + id2, err := is.Create([]byte(`{"comment": "abc2", "rootfs": {"type": "layers"}}`)) + if err != nil { + t.Fatal(err) + } + + id3, err := is.Create([]byte(`{"comment": "abc3", "rootfs": {"type": "layers"}}`)) + if err != nil { + t.Fatal(err) + } + + if err := is.SetParent(id, id2); err != nil { + t.Fatal(err) + } + + ids := is.Children(id2) + if actual, expected := len(ids), 1; expected != actual { + t.Fatalf("wrong number of children: %d, got %d", expected, actual) + } + + if err := is.SetParent(id, id3); err != nil { + t.Fatal(err) + } + + ids = is.Children(id2) + if actual, expected := len(ids), 0; expected != actual { + t.Fatalf("wrong number of children after parent reset: %d, got %d", expected, actual) + } + + ids = is.Children(id3) + if actual, expected := len(ids), 1; expected != actual { + t.Fatalf("wrong number of children after parent reset: %d, got %d", expected, actual) + } + +} + type mockLayerGetReleaser struct{} func (ls *mockLayerGetReleaser) Get(layer.ChainID) (layer.Layer, error) { |