@@ -41,6 +41,7 @@ import (
41
41
"github.com/jonboulle/clockwork"
42
42
"github.com/sirupsen/logrus"
43
43
"github.com/stretchr/testify/require"
44
+ "golang.org/x/sync/errgroup"
44
45
"google.golang.org/grpc"
45
46
"google.golang.org/grpc/credentials"
46
47
"google.golang.org/grpc/credentials/insecure"
@@ -1818,19 +1819,28 @@ func TestInitDatabaseService(t *testing.T) {
1818
1819
cfg .Databases .Enabled = test .enabled
1819
1820
cfg .Databases .Databases = test .databases
1820
1821
1822
+ // This timeout should consider time to receive the event + shutdown
1823
+ // time.
1824
+ ctx , cancel := context .WithTimeout (context .Background (), 20 * time .Second )
1825
+ defer cancel ()
1826
+
1827
+ var eg errgroup.Group
1821
1828
process , err := NewTeleport (cfg )
1822
1829
require .NoError (t , err )
1830
+ require .NoError (t , process .Start ())
1831
+ eg .Go (func () error { return process .WaitForSignals (ctx , nil ) })
1832
+ // Ensures the process is closed in failure scenarios.
1823
1833
t .Cleanup (func () {
1824
- require .NoError (t , process .Close ())
1834
+ cancel ()
1835
+ _ = eg .Wait ()
1825
1836
})
1826
- require .NoError (t , process .Start ())
1827
-
1828
- ctx , cancel := context .WithTimeout (context .Background (), 5 * time .Second )
1829
- defer cancel ()
1830
1837
1831
1838
if ! test .expectErr {
1832
1839
_ , err := process .WaitForEvent (ctx , TeleportReadyEvent )
1833
1840
require .NoError (t , err )
1841
+ require .NoError (t , process .Close ())
1842
+ // Expect Teleport to shutdown without reporting any issue.
1843
+ require .NoError (t , eg .Wait ())
1834
1844
return
1835
1845
}
1836
1846
@@ -1840,6 +1850,9 @@ func TestInitDatabaseService(t *testing.T) {
1840
1850
exitPayload , ok := event .Payload .(ExitEventPayload )
1841
1851
require .True (t , ok , "expected ExitEventPayload but got %T" , event .Payload )
1842
1852
require .Equal (t , "db.init" , exitPayload .Service .Name ())
1853
+ // Database service init is a critical service, meaning failures on
1854
+ // it should cause the process to exit with error.
1855
+ require .Error (t , eg .Wait ())
1843
1856
})
1844
1857
}
1845
1858
}
0 commit comments