Skip to content

Commit

Permalink
fix: Fix counting "lost" bridges. (#869)
Browse files Browse the repository at this point in the history
* fix: Fix counting "lost" bridges.

* test: Add a unit test for "lost bridges".
  • Loading branch information
bgrozev authored Jan 25, 2022
1 parent 7623960 commit 5d9923c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/main/kotlin/org/jitsi/jicofo/bridge/BridgeSelector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class BridgeSelector @JvmOverloads constructor(
* The number of bridges which disconnected without going into graceful shutdown first.
*/
private val lostBridges = AtomicInteger()
fun lostBridges() = lostBridges.get()

/**
* Adds a bridge to this selector, or if a bridge with the given JID
Expand Down Expand Up @@ -110,7 +111,7 @@ class BridgeSelector @JvmOverloads constructor(
fun removeJvbAddress(bridgeJid: Jid) {
logger.info("Removing JVB: $bridgeJid")
bridges.remove(bridgeJid)?.let {
if (it.isInGracefulShutdown) {
if (!it.isInGracefulShutdown) {
lostBridges.incrementAndGet()
}
eventEmitter.fireEvent { bridgeRemoved(it) }
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/mock/util/TestConference.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private void createJvbAndConference(String serverName, EntityBareJid roomName)
mockBridge.start();

Bridge bridge = harness.jicofoServices.getBridgeSelector().addJvbAddress(bridgeJid);
BridgeTestKt.setStats(bridge, 0.0, "region", "version", true /* colibri2 */);
BridgeTestKt.setStats(bridge, 0.0, "region", "version", true /* colibri2 */, false);

createConferenceRoom(roomName);
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/kotlin/org/jitsi/jicofo/bridge/BridgeSelectorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,23 @@ class BridgeSelectorTest : ShouldSpec() {
val jvb2 = selector.addJvbAddress(jid2).apply { setStats(stress = 0.9) }
selector.selectBridge() shouldBe jvb2
}
context("Lost bridges stats") {
val selector = BridgeSelector(clock)
selector.lostBridges() shouldBe 0

val jvb1 = selector.addJvbAddress(jid1)
selector.lostBridges() shouldBe 0

should("Increment the lost bridges stat when a bridge goes away") {
selector.removeJvbAddress(jvb1.jid)
selector.lostBridges() shouldBe 1
}
should("Not increment the lost bridges stat when a bridge in graceful-shutdown goes away") {
jvb1.setStats(gracefulShutdown = true)
selector.removeJvbAddress(jvb1.jid)
selector.lostBridges() shouldBe 0
}
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/test/kotlin/org/jitsi/jicofo/bridge/BridgeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ fun Bridge.setStats(
stress: Double? = null,
region: String? = null,
version: String? = null,
colibri2: Boolean = true
colibri2: Boolean = true,
gracefulShutdown: Boolean = false
) = setStats(
ColibriStatsExtension().apply {
stress?.let { addStat(ColibriStatsExtension.Stat("stress_level", it)) }
Expand All @@ -136,5 +137,6 @@ fun Bridge.setStats(
}
version?.let { addStat(ColibriStatsExtension.Stat("version", version)) }
if (colibri2) addStat("colibri2", "true")
if (gracefulShutdown) addStat(ColibriStatsExtension.SHUTDOWN_IN_PROGRESS, "true")
}
)

0 comments on commit 5d9923c

Please sign in to comment.