Skip to content

Commit

Permalink
#DEOPSCSW-506 : Saloni | Bilal : Improve test for alarm client to add…
Browse files Browse the repository at this point in the history
… asserts for initial conditions

Co-authored-by: Bilal Fazlani <[email protected]>
  • Loading branch information
skvithalani and bilal-fazlani committed Aug 31, 2018
1 parent e8ebcae commit ae07cee
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ class CommandExecutorTest extends AlarmCliTestSetup {
maybeAlarmName = Some(tromboneAxisLowLimitKey.name)
)

getCurrentSeverity(tromboneAxisLowLimitKey).futureValue shouldBe Disconnected
getStatus(tromboneAxisLowLimitKey).futureValue.latchedSeverity shouldBe Disconnected

setSeverity(tromboneAxisLowLimitKey, Major).futureValue
setSeverity(tromboneAxisLowLimitKey, Okay).futureValue
getStatus(tromboneAxisLowLimitKey).futureValue.latchedSeverity shouldBe Major
Expand Down Expand Up @@ -405,7 +408,9 @@ class CommandExecutorTest extends AlarmCliTestSetup {
)

val (subscription, _) = alarmAdminClient.subscribeSeverity(cmd)
Thread.sleep(1000) //wait for subscription to finish
subscription.ready().futureValue

getCurrentSeverity(tromboneAxisHighLimitKey).futureValue shouldBe Disconnected

setSeverity(tromboneAxisHighLimitKey, Major).futureValue
setSeverity(tromboneAxisHighLimitKey, Okay).futureValue
Expand Down Expand Up @@ -510,7 +515,9 @@ class CommandExecutorTest extends AlarmCliTestSetup {
)

val (subscription, _) = alarmAdminClient.subscribeHealth(cmd)
Thread.sleep(1000) //wait for subscription to finish
subscription.ready().futureValue

getCurrentSeverity(tromboneAxisHighLimitKey).futureValue shouldBe Disconnected

setSeverity(tromboneAxisHighLimitKey, Major).futureValue
setSeverity(tromboneAxisHighLimitKey, Okay).futureValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import static org.junit.Assert.*;

// DEOPSCSW-444: Set severity api for component
public class JAlarmServiceImplTest {
public class JSeverityServiceModuleTest {

private static AlarmServiceTestSetup alarmServiceTestSetup = new AlarmServiceTestSetup();
private static IAlarmService jAlarmService = alarmServiceTestSetup.jAlarmService();
Expand Down Expand Up @@ -61,10 +61,10 @@ public void setSeverity_shouldSetSeverityForAGivenKey() throws Exception {
AlarmKey tromboneAxisHighLimitAlarm = new AlarmKey(JSubsystem.NFIRAOS, "trombone", "tromboneAxisHighLimitAlarm");

FullAlarmSeverity initialSeverity = Await.result(alarmService.getCurrentSeverity(tromboneAxisHighLimitAlarm), new FiniteDuration(2, TimeUnit.SECONDS));
assertEquals(initialSeverity, JAlarmSeverity.Disconnected);
assertEquals(JAlarmSeverity.Disconnected, initialSeverity);

AlarmStatus initialStatus = getStatus(tromboneAxisHighLimitAlarm);
assertEquals( AcknowledgementStatus.Acknowledged$.MODULE$,initialStatus.acknowledgementStatus());
assertEquals(AcknowledgementStatus.Acknowledged$.MODULE$,initialStatus.acknowledgementStatus());
assertEquals(JAlarmSeverity.Disconnected,initialStatus.latchedSeverity());

//set severity to Major
Expand Down Expand Up @@ -99,10 +99,10 @@ public void setSeverity_shouldLatchAlarmWhenItIsHigherThanPreviousLatchedSeverit
AlarmKey tromboneAxisHighLimitAlarm = new AlarmKey(JSubsystem.NFIRAOS, "trombone", "tromboneAxisHighLimitAlarm");

FullAlarmSeverity initialSeverity = Await.result(alarmService.getCurrentSeverity(tromboneAxisHighLimitAlarm), new FiniteDuration(2, TimeUnit.SECONDS));
assertEquals(initialSeverity, JAlarmSeverity.Disconnected);
assertEquals(JAlarmSeverity.Disconnected, initialSeverity);

AlarmStatus initialStatus = getStatus(tromboneAxisHighLimitAlarm);
assertEquals( AcknowledgementStatus.Acknowledged$.MODULE$,initialStatus.acknowledgementStatus());
assertEquals(AcknowledgementStatus.Acknowledged$.MODULE$,initialStatus.acknowledgementStatus());
assertEquals(JAlarmSeverity.Disconnected,initialStatus.latchedSeverity());


Expand All @@ -129,7 +129,7 @@ public void setSeverity_shouldNotAutoAcknowledgeAlarmEvenWhenItIsAutoAcknowlegab
AlarmKey tromboneAxisLowLimitAlarm = new AlarmKey(JSubsystem.NFIRAOS, "trombone", "tromboneAxisHighLimitAlarm");

FullAlarmSeverity initialSeverity = Await.result(alarmService.getCurrentSeverity(tromboneAxisLowLimitAlarm), new FiniteDuration(2, TimeUnit.SECONDS));
assertEquals(initialSeverity, JAlarmSeverity.Disconnected);
assertEquals(JAlarmSeverity.Disconnected, initialSeverity);

AlarmStatus initialStatus = getStatus(tromboneAxisLowLimitAlarm);
assertEquals( AcknowledgementStatus.Acknowledged$.MODULE$,initialStatus.acknowledgementStatus());
Expand All @@ -146,16 +146,14 @@ public void setSeverity_shouldNotAutoAcknowledgeAlarmEvenWhenItIsAutoAcknowlegab
public void setSeverity_shouldNotUpdateAlarmTimeWhenSeverityDoesNotChange() throws Exception {
// latchable alarm
AlarmKey highLimitAlarmKey = new AlarmKey(JSubsystem.NFIRAOS, "trombone", "tromboneAxisHighLimitAlarm");

AlarmTime defaultAlarmTime = getStatus(highLimitAlarmKey).alarmTime();

// latch it to major
AlarmStatus status = setSeverityAndGetStatus(highLimitAlarmKey, JAlarmSeverity.Major);
assertTrue(status.alarmTime().time().isAfter(defaultAlarmTime.time()));

// set the severity again to mimic alarm refreshing
AlarmStatus status1 = setSeverityAndGetStatus(highLimitAlarmKey, JAlarmSeverity.Major);

assertEquals(status.alarmTime().time(), status1.alarmTime().time());
assertTrue(status.alarmTime().time().isAfter(defaultAlarmTime.time()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import akka.actor.typed.scaladsl.adapter.UntypedActorSystemOps
import com.typesafe.config.ConfigFactory
import csw.messages.params.models.Subsystem.{BAD, LGSF, NFIRAOS, TCS}
import csw.services.alarm.api.exceptions.{InactiveAlarmException, KeyNotFoundException}
import csw.services.alarm.api.models.{AlarmHealth, AlarmStatus}
import csw.services.alarm.api.models.AlarmHealth
import csw.services.alarm.api.models.AlarmHealth.{Bad, Good, Ill}
import csw.services.alarm.api.models.AlarmSeverity._
import csw.services.alarm.api.models.FullAlarmSeverity.Disconnected
import csw.services.alarm.api.models.Key.{ComponentKey, GlobalKey, SubsystemKey}
import csw.services.alarm.api.models.ShelveStatus.Shelved
import csw.services.alarm.client.internal.helpers.AlarmServiceTestSetup
Expand All @@ -29,6 +30,7 @@ class HealthServiceModuleTest

// DEOPSCSW-466: Fetch health for a given alarm, component name or a subsystem name
test("getAggregatedHealth should get aggregated health for a alarm") {
getCurrentSeverity(tromboneAxisHighLimitAlarmKey).await shouldBe Disconnected
getAggregatedHealth(tromboneAxisHighLimitAlarmKey).await shouldBe Bad

setSeverity(tromboneAxisHighLimitAlarmKey, Okay).await
Expand All @@ -46,6 +48,9 @@ class HealthServiceModuleTest
val tromboneKey = ComponentKey(NFIRAOS, "trombone")
getAggregatedHealth(tromboneKey).await shouldBe Bad

getCurrentSeverity(tromboneAxisHighLimitAlarmKey).await shouldBe Disconnected
getCurrentSeverity(tromboneAxisLowLimitAlarmKey).await shouldBe Disconnected

setSeverity(tromboneAxisHighLimitAlarmKey, Okay).await
setSeverity(tromboneAxisLowLimitAlarmKey, Major).await

Expand All @@ -57,6 +62,9 @@ class HealthServiceModuleTest
val tromboneKey = SubsystemKey(TCS)
getAggregatedHealth(tromboneKey).await shouldBe Bad

getCurrentSeverity(cpuExceededAlarmKey).await shouldBe Disconnected
getCurrentSeverity(outOfRangeOffloadAlarmKey).await shouldBe Disconnected

setSeverity(cpuExceededAlarmKey, Okay).await
setSeverity(outOfRangeOffloadAlarmKey, Major).await

Expand All @@ -70,6 +78,8 @@ class HealthServiceModuleTest
initAlarms(validAlarmsConfig, reset = true).await

getAggregatedHealth(GlobalKey).await shouldBe Bad
getCurrentSeverity(tromboneAxisHighLimitAlarmKey).await shouldBe Disconnected
getCurrentSeverity(tromboneAxisLowLimitAlarmKey).await shouldBe Disconnected

setSeverity(tromboneAxisHighLimitAlarmKey, Okay).await
setSeverity(tromboneAxisLowLimitAlarmKey, Major).await
Expand All @@ -80,8 +90,9 @@ class HealthServiceModuleTest
// DEOPSCSW-448: Set Activation status for an alarm entity
// DEOPSCSW-466: Fetch health for a given alarm, component name or a subsystem name
test("getAggregatedHealth should not consider inactive alarms for health aggregation") {

getAggregatedHealth(GlobalKey).await shouldBe Bad
getCurrentSeverity(enclosureTempLowAlarmKey).await shouldBe Disconnected
getCurrentSeverity(enclosureTempHighAlarmKey).await shouldBe Disconnected

enclosureTempHighAlarm.isActive shouldBe true
setSeverity(enclosureTempHighAlarmKey, Okay).await
Expand All @@ -99,7 +110,8 @@ class HealthServiceModuleTest
val componentKey = ComponentKey(cpuExceededAlarmKey.subsystem, cpuExceededAlarmKey.component)
getAggregatedHealth(componentKey).await shouldBe Bad

setStatus(cpuExceededAlarmKey, AlarmStatus().copy(shelveStatus = Shelved))
shelve(cpuExceededAlarmKey).await
getStatus(cpuExceededAlarmKey).await.shelveStatus shouldBe Shelved

setSeverity(cpuExceededAlarmKey, Okay).await
getAggregatedHealth(componentKey).await shouldBe Good
Expand All @@ -120,16 +132,15 @@ class HealthServiceModuleTest

// DEOPSCSW-468: Monitor health values based on alarm severities for a single alarm, component, subsystem or all
test("subscribe aggregated health via callback for an alarm") {

getAggregatedHealth(GlobalKey).await shouldBe Bad
getCurrentSeverity(tromboneAxisHighLimitAlarmKey).await shouldBe Disconnected
getCurrentSeverity(tromboneAxisLowLimitAlarmKey).await shouldBe Disconnected

// alarm subscription - nfiraos.trombone.tromboneAxisLowLimitAlarm
val testProbe = TestProbe[AlarmHealth]()(actorSystem.toTyped)
val alarmSubscription = subscribeAggregatedHealthCallback(tromboneAxisLowLimitAlarmKey, testProbe.ref ! _)
alarmSubscription.ready().await

Thread.sleep(500) // wait for redis connection to happen

setSeverity(tromboneAxisLowLimitAlarmKey, Major).await

testProbe.expectMessage(Ill)
Expand All @@ -147,16 +158,15 @@ class HealthServiceModuleTest

// DEOPSCSW-468: Monitor health values based on alarm severities for a single alarm, component, subsystem or all
test("subscribe aggregated health via callback for a subsystem") {

getAggregatedHealth(GlobalKey).await shouldBe Bad
getCurrentSeverity(cpuExceededAlarmKey).await shouldBe Disconnected
getCurrentSeverity(tromboneAxisHighLimitAlarmKey).await shouldBe Disconnected

// subsystem subscription - tcs
val testProbe = TestProbe[AlarmHealth]()(actorSystem.toTyped)
val alarmSubscription = subscribeAggregatedHealthCallback(SubsystemKey(TCS), testProbe.ref ! _)
alarmSubscription.ready().await

Thread.sleep(500) // wait for redis connection to happen

setSeverity(cpuExceededAlarmKey, Major).await

testProbe.expectMessage(Ill)
Expand All @@ -170,16 +180,14 @@ class HealthServiceModuleTest

// DEOPSCSW-468: Monitor health values based on alarm severities for a single alarm, component, subsystem or all
test("subscribe aggregated health via callback for a component") {

getAggregatedHealth(GlobalKey).await shouldBe Bad
getCurrentSeverity(tromboneAxisLowLimitAlarmKey).await shouldBe Disconnected

// component subscription - nfiraos.trombone
val testProbe = TestProbe[AlarmHealth]()(actorSystem.toTyped)
val alarmSubscription = subscribeAggregatedHealthCallback(ComponentKey(NFIRAOS, "trombone"), testProbe.ref ! _)
alarmSubscription.ready().await

Thread.sleep(500) // wait for redis connection to happen

setSeverity(tromboneAxisLowLimitAlarmKey, Major).await

testProbe.expectMessage(Ill)
Expand All @@ -191,15 +199,15 @@ class HealthServiceModuleTest
// DEOPSCSW-448: Set Activation status for an alarm entity
// DEOPSCSW-468: Monitor health values based on alarm severities for a single alarm, component, subsystem or all
test("subscribeAggregatedHealthCallback should not consider inactive alarm for aggregation") {

getAggregatedHealth(GlobalKey).await shouldBe Bad
getCurrentSeverity(enclosureTempHighAlarmKey).await shouldBe Disconnected
getCurrentSeverity(enclosureTempLowAlarmKey).await shouldBe Disconnected

val testProbe = TestProbe[AlarmHealth]()(actorSystem.toTyped)
val alarmSubscription =
subscribeAggregatedHealthCallback(ComponentKey(NFIRAOS, "enclosure"), testProbe.ref ! _)
alarmSubscription.ready().await

Thread.sleep(500) // wait for redis connection to happen
enclosureTempHighAlarm.isActive shouldBe true
setSeverity(enclosureTempHighAlarmKey, Okay).await

Expand Down Expand Up @@ -241,16 +249,15 @@ class HealthServiceModuleTest

// DEOPSCSW-468: Monitor health values based on alarm severities for a single alarm, component, subsystem or all
test("subscribe aggregated health via actorRef for a subsystem") {

getAggregatedHealth(GlobalKey).await shouldBe Bad
getCurrentSeverity(cpuExceededAlarmKey).await shouldBe Disconnected
getCurrentSeverity(tromboneAxisHighLimitAlarmKey).await shouldBe Disconnected

// subsystem subscription - tcs
val testProbe = TestProbe[AlarmHealth]()(actorSystem.toTyped)
val alarmSubscription = subscribeAggregatedHealthActorRef(SubsystemKey(TCS), testProbe.ref)
alarmSubscription.ready().await

Thread.sleep(500) // wait for redis connection to happen

setSeverity(cpuExceededAlarmKey, Okay).await

testProbe.expectMessage(Good)
Expand All @@ -264,15 +271,16 @@ class HealthServiceModuleTest

// DEOPSCSW-449: Set Shelve/Unshelve status for alarm entity
test("shelved alarms should be considered in health aggregation") {

getAggregatedHealth(GlobalKey).await shouldBe Bad
getCurrentSeverity(cpuExceededAlarmKey).await shouldBe Disconnected

val testProbe = TestProbe[AlarmHealth]()(actorSystem.toTyped)
val alarmSubscription = subscribeAggregatedHealthActorRef(SubsystemKey(TCS), testProbe.ref)
alarmSubscription.ready().await

// initialize alarm with Shelved status just for this test
setStatus(cpuExceededAlarmKey, AlarmStatus().copy(shelveStatus = Shelved))
shelve(cpuExceededAlarmKey).await
getStatus(cpuExceededAlarmKey).await.shelveStatus shouldBe Shelved

// there is only one alarm in TCS.tcsPk component
setSeverity(cpuExceededAlarmKey, Critical).await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ class MetadataServiceModuleTest
val twoAlarmsConfig: Config = ConfigFactory.parseResources("test-alarms/two-valid-alarms.conf")

test("initAlarms should load alarms from provided config file") {
clearAlarmStore().await
a[KeyNotFoundException] shouldBe thrownBy(getMetadata(GlobalKey).await)

initTestAlarms()

// valid-alarms.conf contains 4 alarms
Expand All @@ -111,6 +114,9 @@ class MetadataServiceModuleTest
}

test("initAlarms should reset the previous alarm data in redis and load with newly provided") {
clearAlarmStore().await
a[KeyNotFoundException] shouldBe thrownBy(getMetadata(GlobalKey).await)

// valid-alarms.conf contains 4 alarms, cpuExceededAlarm is one of them
initAlarms(fourAlarmsConfig, reset = true).await
getMetadata(GlobalKey).await.size shouldBe 4
Expand All @@ -133,6 +139,9 @@ class MetadataServiceModuleTest
}

test("initAlarm with reset should not delete keys other than alarm service, for example sentinel related keys") {
clearAlarmStore().await
a[KeyNotFoundException] shouldBe thrownBy(getMetadata(GlobalKey).await)

// two-valid-alarms.conf contains 2 alarms
initAlarms(twoAlarmsConfig, reset = true).await
getMetadata(GlobalKey).await.size shouldBe 2
Expand All @@ -148,6 +157,9 @@ class MetadataServiceModuleTest
}

test("initAlarm with reset=false should preserve existing alarm keys") {
clearAlarmStore().await
a[KeyNotFoundException] shouldBe thrownBy(getMetadata(GlobalKey).await)

// cpuExceededAlarm present in this file
initAlarms(fourAlarmsConfig, reset = true).await
getMetadata(GlobalKey).await.size shouldBe 4
Expand Down
Loading

0 comments on commit ae07cee

Please sign in to comment.