MCPcopy Index your code
hub / github.com/coder/coder / TestConn_CoordinatorRollingRestart

Function TestConn_CoordinatorRollingRestart

enterprise/coderd/coderd_test.go:1087–1225  ·  view source on GitHub ↗

Test_CoordinatorRollingRestart tests that two peers can maintain a connection without forgetting about each other when a HA coordinator does a rolling restart. We had a few issues with this in the past: 1. We didn't allow clients to maintain their peer ID after a reconnect, which resulted in the ot

(t *testing.T)

Source from the content-addressed store, hash-verified

1085//
1086// This test uses a real server and real clients.
1087func TestConn_CoordinatorRollingRestart(t *testing.T) {
1088 t.Parallel()
1089
1090 // Although DERP will have connection issues until the connection is
1091 // reestablished, any open connections should be maintained.
1092 //
1093 // Direct connections should be able to transmit packets throughout the
1094 // restart without issue.
1095 //nolint:paralleltest // Outdated rule
1096 for _, direct := range []bool{true, false} {
1097 name := "DERP"
1098 if direct {
1099 name = "Direct"
1100 }
1101
1102 t.Run(name, func(t *testing.T) {
1103 t.Parallel()
1104
1105 store, ps := dbtestutil.NewDB(t)
1106 dv := coderdtest.DeploymentValues(t, func(dv *codersdk.DeploymentValues) {
1107 dv.DERP.Config.BlockDirect = serpent.Bool(!direct)
1108 })
1109 logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Leveled(slog.LevelDebug)
1110
1111 // Create two restartable test servers with the same database.
1112 client1, user, s1 := newRestartableTestServer(t, &coderdenttest.Options{
1113 DontAddFirstUser: false,
1114 DontAddLicense: false,
1115 Options: &coderdtest.Options{
1116 Logger: ptr.Ref(logger.Named("server1")),
1117 Database: store,
1118 Pubsub: ps,
1119 DeploymentValues: dv,
1120 IncludeProvisionerDaemon: true,
1121 },
1122 LicenseOptions: &coderdenttest.LicenseOptions{
1123 Features: license.Features{
1124 codersdk.FeatureHighAvailability: 1,
1125 },
1126 },
1127 })
1128 client2, _, s2 := newRestartableTestServer(t, &coderdenttest.Options{
1129 DontAddFirstUser: true,
1130 DontAddLicense: true,
1131 Options: &coderdtest.Options{
1132 Logger: ptr.Ref(logger.Named("server2")),
1133 Database: store,
1134 Pubsub: ps,
1135 DeploymentValues: dv,
1136 },
1137 })
1138 client2.SetSessionToken(client1.SessionToken())
1139
1140 workspace := dbfake.WorkspaceBuild(t, store, database.WorkspaceTable{
1141 OrganizationID: user.OrganizationID,
1142 OwnerID: user.UserID,
1143 }).WithAgent().Do()
1144

Callers

nothing calls this directly

Calls 15

NewDBFunction · 0.92
DeploymentValuesFunction · 0.92
RefFunction · 0.92
WorkspaceBuildFunction · 0.92
NewFunction · 0.92
NewWorkspaceAgentWaiterFunction · 0.92
ContextFunction · 0.92
NewFunction · 0.92
newRestartableTestServerFunction · 0.85
tcpEchoServerFunction · 0.85
writeReadEchoFunction · 0.85
NamedMethod · 0.80

Tested by

no test coverage detected