@@ -1238,3 +1238,77 @@ func Test_ProxyResumeFail(t *testing.T) {
12381238 assert .NotEqual (sessionId , connections [0 ].SessionId ())
12391239 }
12401240}
1241+
1242+ func Test_ProxyUpdateBandwidth (t * testing.T ) {
1243+ t .Parallel ()
1244+ require := require .New (t )
1245+ assert := assert .New (t )
1246+ server := testserver .NewProxyServerForTest (t , "DE" )
1247+ mcu , _ := newMcuProxyForTestWithOptions (t , testserver.ProxyTestOptions {
1248+ Servers : []testserver.ProxyTestServer {server },
1249+ }, 0 , nil )
1250+
1251+ connections := mcu .getSortedConnections (nil )
1252+ require .Len (connections , 1 )
1253+
1254+ ctx , cancel := context .WithTimeout (t .Context (), testTimeout )
1255+ defer cancel ()
1256+
1257+ pubId := api .PublicSessionId ("the-publisher" )
1258+ pubSid := "1234567890"
1259+ pubListener := mock .NewListener (pubId + "-public" )
1260+ pubInitiator := mock .NewInitiator ("DE" )
1261+
1262+ pub , err := mcu .NewPublisher (ctx , pubListener , pubId , pubSid , sfu .StreamTypeVideo , sfu.NewPublisherSettings {
1263+ MediaTypes : sfu .MediaTypeVideo | sfu .MediaTypeAudio ,
1264+ }, pubInitiator )
1265+ require .NoError (err )
1266+
1267+ defer pub .Close (context .Background ())
1268+
1269+ pubBw , ok := pub .(sfu.ClientWithBandwidth )
1270+ require .True (ok )
1271+
1272+ assert .Nil (pubBw .Bandwidth ())
1273+
1274+ client := server .GetSingleClient ()
1275+ require .NotNil (client )
1276+
1277+ client .SendMessage (& proxy.ServerMessage {
1278+ Type : "event" ,
1279+ Event : & proxy.EventServerMessage {
1280+ Type : "update-load" ,
1281+ ClientBandwidths : map [string ]proxy.EventServerBandwidth {
1282+ pub .Id (): {
1283+ Sent : 1000 ,
1284+ Received : 2000 ,
1285+ },
1286+ },
1287+ },
1288+ })
1289+
1290+ // Wait until message has been processed
1291+ bw := pubBw .Bandwidth ()
1292+ for bw == nil {
1293+ require .NoError (ctx .Err ())
1294+ time .Sleep (time .Millisecond )
1295+ bw = pubBw .Bandwidth ()
1296+ }
1297+
1298+ if assert .NotNil (bw ) {
1299+ assert .EqualValues (1000 , bw .Sent )
1300+ assert .EqualValues (2000 , bw .Received )
1301+ }
1302+
1303+ if assert .NoError (pubBw .SetBandwidth (ctx , 3000 )) {
1304+ if serverPub := server .GetPublisher (api .PublicSessionId (pub .Id ())); assert .NotNil (serverPub ) {
1305+ bw := serverPub .Bandwidth ()
1306+ for bw == 0 {
1307+ require .NoError (ctx .Err ())
1308+ time .Sleep (time .Millisecond )
1309+ bw = serverPub .Bandwidth ()
1310+ }
1311+ assert .EqualValues (3000 , bw )
1312+ }
1313+ }
1314+ }
0 commit comments