mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-07 23:00:55 +03:00
ensure no client is connected before running max connections test cases
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user