Skip to content

Commit

Permalink
Merge pull request #1764 from dedis/work-be2-DTavaresA-kickstart-conn…
Browse files Browse the repository at this point in the history
…ection-server-start

[BE2] #1749 Start connection upon start
  • Loading branch information
DanielTavaresA authored Mar 7, 2024
2 parents ec20ed0 + 39c7777 commit a05ef69
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ private class FileMonitor(mediatorRef: ActorRef) extends Runnable {
directory.register(watchService, ENTRY_MODIFY)

override def run(): Unit = {
// Upon start, we connect to the servers
mediatorRef ! ConnectionMediator.ConnectTo(readServerPeers())
try {
while (!Thread.currentThread().isInterrupted) {
// Blocks until an event happen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,38 @@ class MonitorSuite extends TestKit(ActorSystem("MonitorSuiteActorSystem")) with
testProbe.expectMsgType[Monitor.GenerateAndSendHeartbeat](timeout)
}

test("monitor should send ConnectTo() requests to ConnectionMediator upon relevant config file change") {
test("monitor should send a ConnectTo() upon creation") {
val mockConnectionMediator = TestProbe()

// Write to mock server peers config file
val mockConfig = List("mockConfig")
testWriteToServerPeersConfig(mockConfig)

val monitorRef = system.actorOf(Monitor.props(ActorRef.noSender))

// Ping monitor to inform it of ConnectionMediatorRef
mockConnectionMediator.send(monitorRef, ConnectionMediator.Ping())

// Expect first read of the server peers list
mockConnectionMediator.expectMsgType[ConnectionMediator.ConnectTo](timeout)

}

test("monitor should send ConnectTo() requests to ConnectionMediator upon relevant config file change besides first read") {
val mockConnectionMediator = TestProbe()

// Write to mock server peers config file
val mockConfig = List("mockConfig")
testWriteToServerPeersConfig(mockConfig)

val monitorRef = system.actorOf(Monitor.props(ActorRef.noSender))

// Ping monitor to inform it of ConnectionMediatorRef
mockConnectionMediator.send(monitorRef, ConnectionMediator.Ping())

// Expect first read of the server peers list
mockConnectionMediator.expectMsgType[ConnectionMediator.ConnectTo](timeout)

// Expect no message as long as the server peers list is untouched
mockConnectionMediator.expectNoMessage(timeout)

Expand All @@ -121,13 +146,20 @@ class MonitorSuite extends TestKit(ActorSystem("MonitorSuiteActorSystem")) with
mockConnectionMediator.expectMsgType[ConnectionMediator.ConnectTo](timeout)
}

test("monitor should not react upon non relevant events in config directory") {
test("monitor should not react upon non relevant events in config directory besides first read") {
val mockConnectionMediator = TestProbe()
val monitorRef = system.actorOf(Monitor.props(ActorRef.noSender))

// Write to mock server peers config file
val mockConfig = List("mockConfig")
testWriteToServerPeersConfig(mockConfig)

// Ping monitor to inform it of ConnectionMediatorRef
mockConnectionMediator.send(monitorRef, ConnectionMediator.Ping())

// Expect first read of the server peers list
mockConnectionMediator.expectMsgType[ConnectionMediator.ConnectTo](timeout)

// Create new file in the directory
val filePath = Path.of(serverPeersListPath).getParent.toString + File.separator + "DELETE_ME"
val file = new PrintWriter(filePath)
Expand Down

0 comments on commit a05ef69

Please sign in to comment.