ensure no client is connected before running max connections test cases

This commit is contained in:
Nicola Murino
2021-05-11 08:04:57 +02:00
parent c8f7fc9bc9
commit b67cd0d3df
6 changed files with 56 additions and 2 deletions

View File

@@ -919,6 +919,10 @@ func TestMaxConnections(t *testing.T) {
oldValue := common.Config.MaxTotalConnections
common.Config.MaxTotalConnections = 1
assert.Eventually(t, func() bool {
return common.Connections.GetClientConnections() == 0
}, 1000*time.Millisecond, 50*time.Millisecond)
user, _, err := httpdtest.AddUser(getTestUser(), http.StatusCreated)
assert.NoError(t, err)
client := getWebDavClient(user, true, nil)
@@ -944,6 +948,10 @@ func TestMaxPerHostConnections(t *testing.T) {
oldValue := common.Config.MaxPerHostConnections
common.Config.MaxPerHostConnections = 1
assert.Eventually(t, func() bool {
return common.Connections.GetClientConnections() == 0
}, 1000*time.Millisecond, 50*time.Millisecond)
user, _, err := httpdtest.AddUser(getTestUser(), http.StatusCreated)
assert.NoError(t, err)
client := getWebDavClient(user, true, nil)
@@ -1188,7 +1196,7 @@ func TestQuotaLimits(t *testing.T) {
if !assert.NoError(t, err, "username: %v", user.Username) {
info, err := os.Stat(testFilePath)
if assert.NoError(t, err) {
fmt.Printf("local file size %v", info.Size())
fmt.Printf("local file size: %v\n", info.Size())
}
printLatestLogs(20)
}
@@ -2580,7 +2588,19 @@ func createTestFile(path string, size int64) error {
if err != nil {
return err
}
return os.WriteFile(path, content, os.ModePerm)
f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.ModePerm)
if err != nil {
return err
}
_, err = f.Write(content)
if err == nil {
err = f.Sync()
}
if err1 := f.Close(); err1 != nil && err == nil {
err = err1
}
return err
}
func printLatestLogs(maxNumberOfLines int) {