<commit_before>package hyperion

import akka.testkit.TestProbe

import scala.concurrent.duration._
import scala.io.Source

class CollectingActorSpec extends BaseAkkaSpec {
  val CRLF = "\r\n"

  "Receiving the \"IncomingData\"" should {
    "skip data until the first complete Telegram comes in" in {
      val receiver = TestProbe()
      val actor = system.actorOf(CollectingActor.props(receiver.ref), "skip-data")

      actor ! MeterAgent.IncomingData("1-3:0.2.8(42)\r\n!522B\r\n/TEST")

      receiver.expectNoMsg(500 milliseconds)
    }

    "emit only complete Telegrams" in {
      //Arrange
      val receiver = TestProbe()
      val actor = system.actorOf(CollectingActor.props(receiver.ref), "emit-telegrams")

      val source = Source.fromInputStream(getClass.getResourceAsStream("/valid-telegram1.txt"))
      val text = try source.mkString finally source.close()

      val data = text.grouped(15).toIndexedSeq

      // Act
      actor ! MeterAgent.IncomingData("!XXXX" + CRLF) // simulate end of previous message
      for (chunk <- data) {
        Thread.sleep(1000)
        actor ! MeterAgent.IncomingData(chunk)
      }

      // Assert
      val telegram = receiver.expectMsgPF(10 seconds) {
        case TelegramReceived(content) => content
      }
      telegram.checksum shouldBe "522B" // other parsing is tested in P1TelegramParserSpec
    }
  }
}<commit_msg>Don't wait too long between sending parts of the telegram<commit_after>package hyperion

import akka.testkit.TestProbe

import scala.concurrent.duration._
import scala.io.Source

class CollectingActorSpec extends BaseAkkaSpec {
  val CRLF = "\r\n"

  "Receiving the \"IncomingData\"" should {
    "skip data until the first complete Telegram comes in" in {
      val receiver = TestProbe()
      val actor = system.actorOf(CollectingActor.props(receiver.ref), "skip-data")

      actor ! MeterAgent.IncomingData("1-3:0.2.8(42)\r\n!522B\r\n/TEST")

      receiver.expectNoMsg(500 milliseconds)
    }

    "emit only complete Telegrams" in {
      //Arrange
      val receiver = TestProbe()
      val actor = system.actorOf(CollectingActor.props(receiver.ref), "emit-telegrams")

      val source = Source.fromInputStream(getClass.getResourceAsStream("/valid-telegram1.txt"))
      val text = try source.mkString finally source.close()

      val data = text.grouped(15).toIndexedSeq

      // Act
      actor ! MeterAgent.IncomingData("!XXXX" + CRLF) // simulate end of previous message
      for (chunk <- data) {
        Thread.sleep(250)
        actor ! MeterAgent.IncomingData(chunk)
      }

      // Assert
      val telegram = receiver.expectMsgPF(10 seconds) {
        case TelegramReceived(content) => content
      }
      telegram.checksum shouldBe "522B" // other parsing is tested in P1TelegramParserSpec
    }
  }
}
{'fraction_non_alphanumeric': 0.10700319943121223, 'fraction_numerical': 0.018130110202630643, 'mean_word_length': 3.0085470085470085, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '13886', 'n_tokens_mistral': 904, 'n_tokens_neox': 852, 'n_words': 203}