gopkg.in/dotcloud/docker.v1@v1.13.1/daemon/graphdriver/devmapper/devmapper_test.go (about) 1 // +build linux 2 3 package devmapper 4 5 import ( 6 "fmt" 7 "testing" 8 "time" 9 10 "github.com/docker/docker/daemon/graphdriver" 11 "github.com/docker/docker/daemon/graphdriver/graphtest" 12 ) 13 14 func init() { 15 // Reduce the size the the base fs and loopback for the tests 16 defaultDataLoopbackSize = 300 * 1024 * 1024 17 defaultMetaDataLoopbackSize = 200 * 1024 * 1024 18 defaultBaseFsSize = 300 * 1024 * 1024 19 defaultUdevSyncOverride = true 20 if err := graphtest.InitLoopbacks(); err != nil { 21 panic(err) 22 } 23 } 24 25 // This avoids creating a new driver for each test if all tests are run 26 // Make sure to put new tests between TestDevmapperSetup and TestDevmapperTeardown 27 func TestDevmapperSetup(t *testing.T) { 28 graphtest.GetDriver(t, "devicemapper") 29 } 30 31 func TestDevmapperCreateEmpty(t *testing.T) { 32 graphtest.DriverTestCreateEmpty(t, "devicemapper") 33 } 34 35 func TestDevmapperCreateBase(t *testing.T) { 36 graphtest.DriverTestCreateBase(t, "devicemapper") 37 } 38 39 func TestDevmapperCreateSnap(t *testing.T) { 40 graphtest.DriverTestCreateSnap(t, "devicemapper") 41 } 42 43 func TestDevmapperTeardown(t *testing.T) { 44 graphtest.PutDriver(t) 45 } 46 47 func TestDevmapperReduceLoopBackSize(t *testing.T) { 48 tenMB := int64(10 * 1024 * 1024) 49 testChangeLoopBackSize(t, -tenMB, defaultDataLoopbackSize, defaultMetaDataLoopbackSize) 50 } 51 52 func TestDevmapperIncreaseLoopBackSize(t *testing.T) { 53 tenMB := int64(10 * 1024 * 1024) 54 testChangeLoopBackSize(t, tenMB, defaultDataLoopbackSize+tenMB, defaultMetaDataLoopbackSize+tenMB) 55 } 56 57 func testChangeLoopBackSize(t *testing.T, delta, expectDataSize, expectMetaDataSize int64) { 58 driver := graphtest.GetDriver(t, "devicemapper").(*graphtest.Driver).Driver.(*graphdriver.NaiveDiffDriver).ProtoDriver.(*Driver) 59 defer graphtest.PutDriver(t) 60 // make sure data or metadata loopback size are the default size 61 if s := driver.DeviceSet.Status(); s.Data.Total != uint64(defaultDataLoopbackSize) || s.Metadata.Total != uint64(defaultMetaDataLoopbackSize) { 62 t.Fatalf("data or metadata loop back size is incorrect") 63 } 64 if err := driver.Cleanup(); err != nil { 65 t.Fatal(err) 66 } 67 //Reload 68 d, err := Init(driver.home, []string{ 69 fmt.Sprintf("dm.loopdatasize=%d", defaultDataLoopbackSize+delta), 70 fmt.Sprintf("dm.loopmetadatasize=%d", defaultMetaDataLoopbackSize+delta), 71 }, nil, nil) 72 if err != nil { 73 t.Fatalf("error creating devicemapper driver: %v", err) 74 } 75 driver = d.(*graphdriver.NaiveDiffDriver).ProtoDriver.(*Driver) 76 if s := driver.DeviceSet.Status(); s.Data.Total != uint64(expectDataSize) || s.Metadata.Total != uint64(expectMetaDataSize) { 77 t.Fatalf("data or metadata loop back size is incorrect") 78 } 79 if err := driver.Cleanup(); err != nil { 80 t.Fatal(err) 81 } 82 } 83 84 // Make sure devices.Lock() has been release upon return from cleanupDeletedDevices() function 85 func TestDevmapperLockReleasedDeviceDeletion(t *testing.T) { 86 driver := graphtest.GetDriver(t, "devicemapper").(*graphtest.Driver).Driver.(*graphdriver.NaiveDiffDriver).ProtoDriver.(*Driver) 87 defer graphtest.PutDriver(t) 88 89 // Call cleanupDeletedDevices() and after the call take and release 90 // DeviceSet Lock. If lock has not been released, this will hang. 91 driver.DeviceSet.cleanupDeletedDevices() 92 93 doneChan := make(chan bool) 94 95 go func() { 96 driver.DeviceSet.Lock() 97 defer driver.DeviceSet.Unlock() 98 doneChan <- true 99 }() 100 101 select { 102 case <-time.After(time.Second * 5): 103 // Timer expired. That means lock was not released upon 104 // function return and we are deadlocked. Release lock 105 // here so that cleanup could succeed and fail the test. 106 driver.DeviceSet.Unlock() 107 t.Fatalf("Could not acquire devices lock after call to cleanupDeletedDevices()") 108 case <-doneChan: 109 } 110 }