fix a deadlock bug along with unit tests
This commit is contained in:
parent
83d12ed5fa
commit
05ce0c01e3
@ -183,6 +183,7 @@ func (self *InMemoryStorage) Samples(name string, numSamples int) ([]*info.Conta
|
|||||||
var ok bool
|
var ok bool
|
||||||
self.lock.RLock()
|
self.lock.RLock()
|
||||||
if cstore, ok = self.containerStorageMap[name]; !ok {
|
if cstore, ok = self.containerStorageMap[name]; !ok {
|
||||||
|
self.lock.RUnlock()
|
||||||
return nil, fmt.Errorf("unable to find data for container %v", name)
|
return nil, fmt.Errorf("unable to find data for container %v", name)
|
||||||
}
|
}
|
||||||
self.lock.RUnlock()
|
self.lock.RUnlock()
|
||||||
@ -195,6 +196,7 @@ func (self *InMemoryStorage) RecentStats(name string, numStats int) ([]*info.Con
|
|||||||
var ok bool
|
var ok bool
|
||||||
self.lock.RLock()
|
self.lock.RLock()
|
||||||
if cstore, ok = self.containerStorageMap[name]; !ok {
|
if cstore, ok = self.containerStorageMap[name]; !ok {
|
||||||
|
self.lock.RUnlock()
|
||||||
return nil, fmt.Errorf("unable to find data for container %v", name)
|
return nil, fmt.Errorf("unable to find data for container %v", name)
|
||||||
}
|
}
|
||||||
self.lock.RUnlock()
|
self.lock.RUnlock()
|
||||||
@ -207,6 +209,7 @@ func (self *InMemoryStorage) Percentiles(name string, cpuPercentiles, memPercent
|
|||||||
var ok bool
|
var ok bool
|
||||||
self.lock.RLock()
|
self.lock.RLock()
|
||||||
if cstore, ok = self.containerStorageMap[name]; !ok {
|
if cstore, ok = self.containerStorageMap[name]; !ok {
|
||||||
|
self.lock.RUnlock()
|
||||||
return nil, fmt.Errorf("unable to find data for container %v", name)
|
return nil, fmt.Errorf("unable to find data for container %v", name)
|
||||||
}
|
}
|
||||||
self.lock.RUnlock()
|
self.lock.RUnlock()
|
||||||
|
@ -61,3 +61,15 @@ func TestRetrievePartialRecentStats(t *testing.T) {
|
|||||||
func TestRetrieveAllRecentStats(t *testing.T) {
|
func TestRetrieveAllRecentStats(t *testing.T) {
|
||||||
runStorageTest(test.StorageDriverTestRetrieveAllRecentStats, t)
|
runStorageTest(test.StorageDriverTestRetrieveAllRecentStats, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNoRecentStats(t *testing.T) {
|
||||||
|
runStorageTest(test.StorageDriverTestNoRecentStats, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoSamples(t *testing.T) {
|
||||||
|
runStorageTest(test.StorageDriverTestNoSamples, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPercentilesWithoutStats(t *testing.T) {
|
||||||
|
runStorageTest(test.StorageDriverTestPercentilesWithoutStats, t)
|
||||||
|
}
|
||||||
|
@ -319,3 +319,43 @@ func StorageDriverTestRetrieveAllRecentStats(driver storage.StorageDriver, t *te
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func StorageDriverTestNoRecentStats(driver storage.StorageDriver, t *testing.T) {
|
||||||
|
defer driver.Close()
|
||||||
|
nonExistContainer := "somerandomecontainer"
|
||||||
|
stats, _ := driver.RecentStats(nonExistContainer, -1)
|
||||||
|
if len(stats) > 0 {
|
||||||
|
t.Errorf("RecentStats() returns %v stats on non exist container", len(stats))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func StorageDriverTestNoSamples(driver storage.StorageDriver, t *testing.T) {
|
||||||
|
defer driver.Close()
|
||||||
|
nonExistContainer := "somerandomecontainer"
|
||||||
|
samples, _ := driver.Samples(nonExistContainer, -1)
|
||||||
|
if len(samples) > 0 {
|
||||||
|
t.Errorf("Samples() returns %v samples on non exist container", len(samples))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func StorageDriverTestPercentilesWithoutStats(driver storage.StorageDriver, t *testing.T) {
|
||||||
|
defer driver.Close()
|
||||||
|
nonExistContainer := "somerandomecontainer"
|
||||||
|
percentiles, _ := driver.Percentiles(nonExistContainer, []int{50, 80}, []int{50, 80})
|
||||||
|
if percentiles == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if percentiles.MaxMemoryUsage != 0 {
|
||||||
|
t.Errorf("Percentiles() reports max memory usage > 0 when there's no stats.")
|
||||||
|
}
|
||||||
|
for _, p := range percentiles.CpuUsagePercentiles {
|
||||||
|
if p.Value != 0 {
|
||||||
|
t.Errorf("Percentiles() reports cpu usage is %v when there's no stats.", p.Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, p := range percentiles.MemoryUsagePercentiles {
|
||||||
|
if p.Value != 0 {
|
||||||
|
t.Errorf("Percentiles() reports memory usage is %v when there's no stats.", p.Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user