async def test_exit_cancels_timer(self):
     refreshed_token = create_access_token(
         generate_token_with_custom_expiry(30 * 60))
     refresher = MagicMock(return_value=refreshed_token)
     expired_token = generate_token_with_custom_expiry(-10 * 60)
     credential = CommunicationTokenCredential(expired_token,
                                               token_refresher=refresher,
                                               proactive_refresh=True)
     credential.get_token()
     credential.close()
     assert credential._timer is not None
     assert refresher.call_count == 0
     assert credential._timer is not None
    async def test_exit_enter_scenario_throws_exception(self):
        refreshed_token = create_access_token(
            generate_token_with_custom_expiry(30 * 60))
        refresher = MagicMock(return_value=refreshed_token)
        expired_token = generate_token_with_custom_expiry(-10 * 60)
        credential = CommunicationTokenCredential(expired_token,
                                                  token_refresher=refresher,
                                                  proactive_refresh=True)
        credential.get_token()
        credential.close()
        assert credential._timer is not None

        with pytest.raises(RuntimeError) as err:
            credential.get_token()
        assert str(
            err.value
        ) == "An instance of CommunicationTokenCredential cannot be reused once it has been closed."