Ejemplo n.º 1
0
TEST_F(WebsocketTest, CleanShutdown) {
  AutoRequired<WebsocketExceptionFilter>();
  
  // Try starting and stopping server multiple times
  {
    AutoCreateContext ctxt;
    CurrentContextPusher pshr(ctxt);
    AutoRequired<AutoNetServer>();
    
    ctxt->Initiate();
    ctxt->Wait(std::chrono::milliseconds(200));
    ctxt->SignalShutdown(true);
  }
  
  {
    AutoCreateContext ctxt;
    CurrentContextPusher pshr(ctxt);
    AutoRequired<AutoNetServer>();
    
    ctxt->Initiate();
    ctxt->Wait(std::chrono::milliseconds(200));
    ctxt->SignalShutdown(true);
  }
  
  {
    AutoCreateContext ctxt;
    CurrentContextPusher pshr(ctxt);
    AutoRequired<AutoNetServer>();
    
    ctxt->Initiate();
    ctxt->Wait(std::chrono::milliseconds(200));
    ctxt->SignalShutdown(true);
  }
}
Ejemplo n.º 2
0
TEST_F(AutoPacketFactoryTest, AutoPacketFactoryCycle) {
  AutoCurrentContext()->Initiate();

  std::weak_ptr<CoreContext> ctxtWeak;
  std::weak_ptr<HoldsAutoPacketFactoryReference> hapfrWeak;
  std::shared_ptr<AutoPacket> packet;

  {
    // Create a context, fill it up, kick it off:
    AutoCreateContext ctxt;
    CurrentContextPusher pshr(ctxt);
    AutoRequired<HoldsAutoPacketFactoryReference> hapfr(ctxt);
    ctxt->Initiate();

    // A weak pointer is used to detect object destruction
    ctxtWeak = ctxt;
    hapfrWeak = hapfr;

    // Trivial validation-of-reciept:
    AutoRequired<AutoPacketFactory> factory;
    {
      auto trivial = factory->NewPacket();
      trivial->Decorate((int) 54);
      ASSERT_EQ(54, hapfr->m_value) << "A simple packet was not received as expected by an AutoFilter";
    }

    // Create a packet which will force in a back-reference:
    packet = factory->NewPacket();

    // Terminate the context:
    ctxt->SignalShutdown();

    // Verify that we can still decorate the packet and also that the packet is delivered to the factory:
    packet->Decorate((int) 55);

    // Relock, verify the value was received by the hapfr:
    ASSERT_EQ(55, hapfr->m_value) << "AutoFilter did not receive a packet as expected";
  }

  // The context cannot go out of socpe until all packets in the context are out of scope
  ASSERT_FALSE(ctxtWeak.expired()) << "Context went out of scope before all packets were finished being processed";

  // Now we can release the packet and verify that everything gets cleaned up:
  packet.reset();
  ASSERT_TRUE(ctxtWeak.expired()) << "AutoPacketFactory incorrectly held a cyclic reference even after the context was shut down";
  ASSERT_TRUE(hapfrWeak.expired()) << "The last packet from a factory was released; this should have resulted in teardown, but it did not";
}
Ejemplo n.º 3
0
TEST_F(CoreContextTest, InitiateAssertsSignals) {
  AutoCurrentContext outer;

  auto teardown = std::make_shared<bool>(false);
  {
    AutoCreateContext ctxt;
    auto initiated = std::make_shared<bool>(false);
    auto running = std::make_shared<bool>(false);
    auto shutdown = std::make_shared<bool>(false);

    ctxt->onInitiated += [initiated] { *initiated = true; };
    ctxt->onRunning += [running] { *running = true; };
    ctxt->onShutdown += [shutdown] { *shutdown = true; };
    ctxt->onTeardown += [teardown] (const CoreContext&) { *teardown = true; };

    ctxt->Initiate();
    ASSERT_TRUE(*initiated) << "Initiation signal not asserted on context startup";
    ASSERT_FALSE(*running) << "Running signal asserted before the outer context was started";
    ASSERT_FALSE(*shutdown) << "Termination signal asserted prematurely";
    *initiated = false;

    outer->Initiate();
    ASSERT_FALSE(*initiated) << "Initiation signal was redundantly asserted";
    ASSERT_TRUE(*running) << "Running signal not asserted when the outer context was started";
    ASSERT_FALSE(*shutdown) << "Termination signal asserted prematurely";

    *running = false;

    ctxt->Initiate();
    ASSERT_FALSE(*initiated) << "Initiation signal redundantly asserted";
    ASSERT_FALSE(*running) << "Running signal redundantly asserted";
    ASSERT_FALSE(*shutdown) << "Termination signal asserted unexpectedly";

    ctxt->SignalShutdown();
    ASSERT_FALSE(*initiated) << "Initiation signal not asserted during teardown";
    ASSERT_FALSE(*running) << "Running signal asserted improperly on teardown";
    ASSERT_TRUE(*shutdown) << "Termination signal not asserted as expected";

    ASSERT_FALSE(*teardown) << "Teardown handler notified prematurely";
  }
  ASSERT_TRUE(*teardown) << "Teardown handler not correctly notified on context teardown";
}