2017-08-18 16:34:04 +03:00
package integration
import (
2019-01-16 17:00:09 +03:00
"fmt"
2022-05-17 16:48:08 +03:00
"net"
2017-08-18 16:34:04 +03:00
"net/http"
2024-01-09 19:00:07 +03:00
"testing"
2017-08-18 16:34:04 +03:00
"time"
2024-01-09 19:00:07 +03:00
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
2023-02-03 17:24:05 +03:00
"github.com/traefik/traefik/v3/integration/try"
2017-08-18 16:34:04 +03:00
)
type TimeoutSuite struct { BaseSuite }
2024-01-09 19:00:07 +03:00
func TestTimeoutSuite ( t * testing . T ) {
suite . Run ( t , new ( TimeoutSuite ) )
2017-08-18 16:34:04 +03:00
}
2024-01-09 19:00:07 +03:00
func ( s * TimeoutSuite ) SetupSuite ( ) {
s . BaseSuite . SetupSuite ( )
2017-08-18 16:34:04 +03:00
2024-01-09 19:00:07 +03:00
s . createComposeProject ( "timeout" )
s . composeUp ( )
}
func ( s * TimeoutSuite ) TearDownSuite ( ) {
s . BaseSuite . TearDownSuite ( )
}
func ( s * TimeoutSuite ) TestForwardingTimeouts ( ) {
timeoutEndpointIP := s . getComposeServiceIP ( "timeoutEndpoint" )
file := s . adaptFile ( "fixtures/timeout/forwarding_timeouts.toml" , struct { TimeoutEndpoint string } { timeoutEndpointIP } )
s . traefikCmd ( withConfigFile ( file ) )
2017-08-18 16:34:04 +03:00
2024-01-09 19:00:07 +03:00
err := try . GetRequest ( "http://127.0.0.1:8080/api/rawdata" , 60 * time . Second , try . BodyContains ( "Path(`/dialTimeout`)" ) )
require . NoError ( s . T ( ) , err )
2017-08-18 16:34:04 +03:00
// This simulates a DialTimeout when connecting to the backend server.
response , err := http . Get ( "http://127.0.0.1:8000/dialTimeout" )
2024-01-09 19:00:07 +03:00
require . NoError ( s . T ( ) , err )
assert . Equal ( s . T ( ) , http . StatusGatewayTimeout , response . StatusCode )
2017-08-18 16:34:04 +03:00
2019-01-16 17:00:09 +03:00
// Check that timeout service is available
2022-05-17 16:48:08 +03:00
statusURL := fmt . Sprintf ( "http://%s/statusTest?status=200" ,
net . JoinHostPort ( timeoutEndpointIP , "9000" ) )
2024-01-09 19:00:07 +03:00
assert . NoError ( s . T ( ) , try . GetRequest ( statusURL , 60 * time . Second , try . StatusCodeIs ( http . StatusOK ) ) )
2019-01-16 17:00:09 +03:00
2017-08-18 16:34:04 +03:00
// This simulates a ResponseHeaderTimeout.
response , err = http . Get ( "http://127.0.0.1:8000/responseHeaderTimeout?sleep=1000" )
2024-01-09 19:00:07 +03:00
require . NoError ( s . T ( ) , err )
assert . Equal ( s . T ( ) , http . StatusGatewayTimeout , response . StatusCode )
2017-08-18 16:34:04 +03:00
}