-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathidle_timeout_transfer_test.go
More file actions
66 lines (54 loc) · 2.25 KB
/
idle_timeout_transfer_test.go
File metadata and controls
66 lines (54 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package ftpserver
import (
"bytes"
"testing"
"time"
"github.com/secsy/goftp"
"github.com/stretchr/testify/require"
)
// TestIdleTimeoutDuringTransfer verifies that the idle timeout doesn't close
// the control connection when a data transfer is active.
func TestIdleTimeoutDuringTransfer(t *testing.T) {
// Create a server with a very short idle timeout
// The test driver adds 500ms delay for files with "delay-io" in the name
server := NewTestServerWithTestDriver(t, &TestServerDriver{
Debug: true,
Settings: &Settings{
IdleTimeout: 1, // 1 second idle timeout
},
})
conf := goftp.Config{
User: authUser,
Password: authPass,
}
client, err := goftp.DialConfig(conf, server.Addr())
require.NoError(t, err, "Couldn't connect")
defer func() { panicOnError(client.Close()) }()
// Create test data - size chosen so that with 500ms delays per read,
// the transfer will take longer than the 1 second idle timeout
data := make([]byte, 1024*1024) // 1MB
for i := range data {
data[i] = byte(i % 256)
}
// Upload the file with "delay-io" in the name to trigger slow I/O
// This will cause each Read() operation to take 500ms
err = client.Store("delay-io-test.bin", bytes.NewReader(data))
require.NoError(t, err, "Failed to upload file")
// Download the file - this will trigger multiple 500ms delays
// Total time will exceed the 1 second idle timeout
// The server should extend the deadline during the active transfer
buf := &bytes.Buffer{}
start := time.Now()
err = client.Retrieve("delay-io-test.bin", buf)
elapsed := time.Since(start)
require.NoError(t, err, "Transfer should succeed despite idle timeout")
require.Equal(t, len(data), buf.Len(), "Downloaded data should match uploaded data")
require.Equal(t, data, buf.Bytes(), "Downloaded content should match uploaded content")
// Verify the transfer took longer than the idle timeout
// This proves the deadline was extended during the transfer
require.Greater(t, elapsed, time.Duration(server.settings.IdleTimeout)*time.Second,
"Transfer should take longer than idle timeout to verify deadline extension worked")
// Verify the connection is still alive after the transfer
_, err = client.ReadDir("/")
require.NoError(t, err, "Connection should still be alive after long transfer")
}