lte/gateway/c/session_manager/test/test_sessiond_integ.cpp
/**
 * End to end test with cloud service intermittent.
 * 1) Create session, respond with 2 charging keys
 * 2) Report rule stats, charging key 1 goes over
 *    Expect update with charging key 1
 * 3) Cloud will respond with a timeout
 * 4) Report rule stats for charging key 1 again
 *    Since the last update failed, this will trigger another update
 * 5) Expect update with usage from both (2) and (4).
 */
End to end test with cloud service intermittent.
1) Create session, respond with 2 charging keys
2) Report rule stats, charging key 1 goes over
Expect update with charging key 1
3) Cloud will respond with a timeout
4) Report rule stats for charging key 1 again
Since the last update failed, this will trigger another update
5) Expect update with usage from both (2) and (4).
End to end test with cloud service intermittent . 1 ) Create session respond with 2 charging keys 2 ) Report rule stats charging key 1 goes over Expect update with charging key 1 3 ) Cloud will respond with a timeout 4 ) Report rule stats for charging key 1 again Since the last update failed this will trigger another update 5 ) Expect update with usage from both ( 2 ) and ( 4 ) .
TEST_F(SessiondTest, end_to_end_cloud_down) {
  std::promise<void> failed_update_promise;
  std::promise<std::string> session_id_promise;
  auto end_promise = std::make_shared<std::promise<void>>();
  uint32_t default_bearer = 5;
  uint32_t enb_teid = TEID_1_DL;
  uint32_t agw_teid = TEID_1_UL;
  auto channel = ServiceRegistrySingleton::Instance()->GetGrpcChannel(
      "sessiond", ServiceRegistrySingleton::LOCAL);
  auto stub = LocalSessionManager::NewStub(channel);
  send_empty_pipelined_table(stub);
  wait_for_setup_calls();
  {
    EXPECT_CALL(*controller_mock,
                CreateSession(testing::_,
                              CheckCreateSession(IMSI1, &session_id_promise),
                              testing::_))
        .Times(1)
        .WillOnce(testing::DoAll(SetCreateSessionResponse(1025, 1024),
                                 testing::Return(grpc::Status::OK)));
  }
  grpc::ClientContext create_context;
  LocalCreateSessionResponse create_resp;
  LocalCreateSessionRequest request;
  request.mutable_common_context()->mutable_sid()->set_id(IMSI1);
  request.mutable_common_context()->set_rat_type(RATType::TGPP_LTE);
  request.mutable_rat_specific_context()->mutable_lte_context()->set_bearer_id(
      default_bearer);
  stub->CreateSession(&create_context, request, &create_resp);
  grpc::ClientContext tun_update_context;
  UpdateTunnelIdsResponse tun_update_response;
  UpdateTunnelIdsRequest tun_update_request;
  tun_update_request.mutable_sid()->set_id(IMSI1);
  tun_update_request.set_bearer_id(default_bearer);
  tun_update_request.set_enb_teid(enb_teid);
  tun_update_request.set_agw_teid(agw_teid);
  stub->UpdateTunnelIds(&tun_update_context, tun_update_request,
                        &tun_update_response);
  {
    CreditUsageUpdate expected_update_fail;
    create_usage_update(IMSI1, 1, 512, 512, CreditUsage::QUOTA_EXHAUSTED,
                        &expected_update_fail);
    EXPECT_CALL(
        *controller_mock,
        UpdateSession(testing::_, CheckSingleUpdate(expected_update_fail),
                      testing::_))
        .Times(1)
        .WillOnce(
            testing::Return(grpc::Status(grpc::DEADLINE_EXCEEDED, "timeout")));
  }
  RuleRecordTable table1;
  create_rule_record(IMSI1, "rule1", 0, 512, table1.mutable_records()->Add());
  create_rule_record(IMSI1, "rule2", 512, 0, table1.mutable_records()->Add());
  send_update_pipelined_table(stub, table1);
  std::this_thread::sleep_for(std::chrono::milliseconds(100));
  {
    CreditUsageUpdate expected_update_success;
    create_usage_update(IMSI1, 1, 1024, 1024, CreditUsage::QUOTA_EXHAUSTED,
                        &expected_update_success);
    EXPECT_CALL(
        *controller_mock,
        UpdateSession(testing::_, CheckSingleUpdate(expected_update_success),
                      testing::_))
        .Times(1)
        .WillOnce(SetEndPromise(end_promise, Status::OK));
  }
  RuleRecordTable table2;
  create_rule_record(IMSI1, "rule1", 512, 512, table2.mutable_records()->Add());
  create_rule_record(IMSI1, "rule2", 512, 512, table2.mutable_records()->Add());
  send_update_pipelined_table(stub, table2);
  set_timeout(5000, end_promise);
  end_promise->get_future().get();
}
TEST_F ( SessiondTest , end_to_end_cloud_down ) { std :: promise < void > failed_update_promise ; std :: promise < std :: string > session_id_promise ; auto end_promise = std :: make_shared < std :: promise < void > > ( ) ; uint32_t default_bearer = 5 ; uint32_t enb_teid = TEID_1_DL ; uint32_t agw_teid = TEID_1_UL ; auto channel = ServiceRegistrySingleton :: Instance ( ) -> GetGrpcChannel ( " " , ServiceRegistrySingleton :: LOCAL ) ; auto stub = LocalSessionManager :: NewStub ( channel ) ; send_empty_pipelined_table ( stub ) ; wait_for_setup_calls ( ) ; { EXPECT_CALL ( * controller_mock , CreateSession ( testing :: _ , CheckCreateSession ( IMSI1 , & session_id_promise ) , testing :: _ ) ) . Times ( 1 ) . WillOnce ( testing :: DoAll ( SetCreateSessionResponse ( 1025 , 1024 ) , testing :: Return ( grpc :: Status :: OK ) ) ) ; } grpc :: ClientContext create_context ; LocalCreateSessionResponse create_resp ; LocalCreateSessionRequest request ; request . mutable_common_context ( ) -> mutable_sid ( ) -> set_id ( IMSI1 ) ; request . mutable_common_context ( ) -> set_rat_type ( RATType :: TGPP_LTE ) ; request . mutable_rat_specific_context ( ) -> mutable_lte_context ( ) -> set_bearer_id ( default_bearer ) ; stub -> CreateSession ( & create_context , request , & create_resp ) ; grpc :: ClientContext tun_update_context ; UpdateTunnelIdsResponse tun_update_response ; UpdateTunnelIdsRequest tun_update_request ; tun_update_request . mutable_sid ( ) -> set_id ( IMSI1 ) ; tun_update_request . set_bearer_id ( default_bearer ) ; tun_update_request . set_enb_teid ( enb_teid ) ; tun_update_request . set_agw_teid ( agw_teid ) ; stub -> UpdateTunnelIds ( & tun_update_context , tun_update_request , & tun_update_response ) ; { CreditUsageUpdate expected_update_fail ; create_usage_update ( IMSI1 , 1 , 512 , 512 , CreditUsage :: QUOTA_EXHAUSTED , & expected_update_fail ) ; EXPECT_CALL ( * controller_mock , UpdateSession ( testing :: _ , CheckSingleUpdate ( expected_update_fail ) , testing :: _ ) ) . Times ( 1 ) . WillOnce ( testing :: Return ( grpc :: Status ( grpc :: DEADLINE_EXCEEDED , " " ) ) ) ; } RuleRecordTable table1 ; create_rule_record ( IMSI1 , " " , 0 , 512 , table1 . mutable_records ( ) -> Add ( ) ) ; create_rule_record ( IMSI1 , " " , 512 , 0 , table1 . mutable_records ( ) -> Add ( ) ) ; send_update_pipelined_table ( stub , table1 ) ; std :: this_thread :: sleep_for ( std :: chrono :: milliseconds ( 100 ) ) ; { CreditUsageUpdate expected_update_success ; create_usage_update ( IMSI1 , 1 , 1024 , 1024 , CreditUsage :: QUOTA_EXHAUSTED , & expected_update_success ) ; EXPECT_CALL ( * controller_mock , UpdateSession ( testing :: _ , CheckSingleUpdate ( expected_update_success ) , testing :: _ ) ) . Times ( 1 ) . WillOnce ( SetEndPromise ( end_promise , Status :: OK ) ) ; } RuleRecordTable table2 ; create_rule_record ( IMSI1 , " " , 512 , 512 , table2 . mutable_records ( ) -> Add ( ) ) ; create_rule_record ( IMSI1 , " " , 512 , 512 , table2 . mutable_records ( ) -> Add ( ) ) ; send_update_pipelined_table ( stub , table2 ) ; set_timeout ( 5000 , end_promise ) ; end_promise -> get_future ( ) . get ( ) ; }
End to end test with cloud service intermittent.
End to end test with cloud service intermittent .
// Setup the SessionD/PipelineD epoch value by sending an empty record. This // will prevent SessionD thinking that PipelineD has restarted mid-test. // Expect create session with IMSI1 // 1- Create session // 2- UpdateTunnelIds Trigger // Expect update with IMSI1, charging key 1, return timeout from cloud // Need to wait for cloud response to come back and usage monitor to reset. // Unfortunately, there is no simple way to wait for response to come back // then callback to be called in event base // second update should contain the original usage report + new usage // report since the first update failed