Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some test fixing #200

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/commands-handler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
name: Process command
if: github.event.issue.pull_request && endsWith(github.repository, '-private') != true
runs-on:
group: Default
group: organization/Default
steps:
- name: Check referred user
id: user-check
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: Check release required
if: github.event.pull_request.merged && endsWith(github.repository, '-private') != true
runs-on:
group: Default
group: organization/Default
outputs:
release: ${{ steps.check.outputs.ready }}
steps:
Expand All @@ -31,7 +31,7 @@ jobs:
needs: check-release
if: needs.check-release.outputs.release == 'true'
runs-on:
group: Default
group: organization/Default
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
tests:
name: Integration and Unit tests
runs-on:
group: Default
group: organization/Default
strategy:
max-parallel: 1
fail-fast: true
Expand Down Expand Up @@ -54,7 +54,7 @@ jobs:
acceptance-tests:
name: Acceptance tests
runs-on:
group: Default
group: organization/Default
timeout-minutes: 5
steps:
- name: Checkout project
Expand Down Expand Up @@ -103,7 +103,7 @@ jobs:
name: Tests
needs: [tests, acceptance-tests]
runs-on:
group: Default
group: organization/Default
steps:
- name: Tests summary
run: echo -e "\033[38;2;95;215;0m\033[1mAll tests successfully passed"
6 changes: 3 additions & 3 deletions .github/workflows/run-validations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
lint:
name: Lint project
runs-on:
group: Default
group: organization/Default
steps:
- name: Checkout project
uses: actions/checkout@v4
Expand All @@ -24,7 +24,7 @@ jobs:
pubnub-yml:
name: "Validate .pubnub.yml"
runs-on:
group: Default
group: organization/Default
steps:
- name: Checkout project
uses: actions/checkout@v4
Expand All @@ -46,7 +46,7 @@ jobs:
name: Validations
needs: [pubnub-yml, lint]
runs-on:
group: Default
group: organization/Default
steps:
- name: Validations summary
run: echo -e "\033[38;2;95;215;0m\033[1mAll validations passed"
18 changes: 7 additions & 11 deletions pubnub/pubnub_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ async def close_pending_tasks(self, tasks):
await asyncio.sleep(0.1)

async def create_session(self):
self._session = aiohttp.ClientSession(
loop=self.event_loop,
timeout=aiohttp.ClientTimeout(connect=self.config.connect_timeout),
connector=self._connector
)
if not self._session:
Copy link

@jguz-pubnub jguz-pubnub Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it mean you will create a new session from now on if it's not presented before? What's the reason behind it? I mean why you had to change it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some time ago I made this mistake of not having a single session connection, so this is the attempt to fix it

self._session = aiohttp.ClientSession(
loop=self.event_loop,
timeout=aiohttp.ClientTimeout(connect=self.config.connect_timeout),
connector=self._connector
)

async def close_session(self):
if self._session is not None:
Expand All @@ -76,12 +77,7 @@ async def set_connector(self, cn):
await self._session.close()

self._connector = cn

self._session = aiohttp.ClientSession(
loop=self.event_loop,
timeout=aiohttp.ClientTimeout(connect=self.config.connect_timeout),
connector=self._connector
)
await self.create_session()

async def stop(self):
if self._subscription_manager:
Expand Down
6 changes: 3 additions & 3 deletions tests/integrational/asyncio/test_fire.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import pytest

from tests.helper import pnconf_copy
from tests.helper import pnconf_env_copy
from tests.integrational.vcr_helper import pn_vcr
from pubnub.pubnub_asyncio import PubNubAsyncio, AsyncioEnvelope
from pubnub.models.consumer.pubsub import PNFireResult
from pubnub.models.consumer.common import PNStatus


@pn_vcr.use_cassette(
'tests/integrational/fixtures/asyncio/publish/fire_get.yaml',
'tests/integrational/fixtures/asyncio/publish/fire_get.json', serializer='pn_json',
filter_query_parameters=['uuid', 'seqn', 'pnsdk']
)
@pytest.mark.asyncio
async def test_single_channel(event_loop):
config = pnconf_copy()
config = pnconf_env_copy()
config.enable_subscribe = False
pn = PubNubAsyncio(config, custom_event_loop=event_loop)
chan = 'unique_sync'
Expand Down
66 changes: 33 additions & 33 deletions tests/integrational/asyncio/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pubnub.models.consumer.common import PNStatus
from pubnub.models.consumer.pubsub import PNPublishResult
from pubnub.pubnub_asyncio import PubNubAsyncio, AsyncioEnvelope, PubNubAsyncioException
from tests.helper import pnconf_copy, pnconf_enc_copy, pnconf_pam_copy
from tests.helper import pnconf_enc_env_copy, pnconf_pam_env_copy, pnconf_env_copy
from tests.integrational.vcr_helper import pn_vcr

pn.set_stream_logger('pubnub', logging.DEBUG)
Expand Down Expand Up @@ -47,12 +47,12 @@ async def assert_success_publish_post(pubnub, msg):


@pn_vcr.use_cassette(
'tests/integrational/fixtures/asyncio/publish/mixed_via_get.yaml',
filter_query_parameters=['uuid', 'seqn', 'pnsdk']
'tests/integrational/fixtures/asyncio/publish/mixed_via_get.json', serializer='pn_json',
filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'l_pub']
)
@pytest.mark.asyncio
async def test_publish_mixed_via_get(event_loop):
pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop)
pubnub = PubNubAsyncio(pnconf_env_copy(), custom_event_loop=event_loop)
await asyncio.gather(
asyncio.ensure_future(assert_success_publish_get(pubnub, "hi")),
asyncio.ensure_future(assert_success_publish_get(pubnub, 5)),
Expand All @@ -64,24 +64,24 @@ async def test_publish_mixed_via_get(event_loop):


@pn_vcr.use_cassette(
'tests/integrational/fixtures/asyncio/publish/object_via_get.yaml',
'tests/integrational/fixtures/asyncio/publish/object_via_get.json', serializer='pn_json',
filter_query_parameters=['uuid', 'seqn', 'pnsdk'],
match_on=['method', 'scheme', 'host', 'port', 'object_in_path', 'query']
)
@pytest.mark.asyncio
async def test_publish_object_via_get(event_loop):
pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop)
pubnub = PubNubAsyncio(pnconf_env_copy(), custom_event_loop=event_loop)
await asyncio.ensure_future(assert_success_publish_get(pubnub, {"name": "Alex", "online": True}))

await pubnub.stop()


@pn_vcr.use_cassette(
'tests/integrational/fixtures/asyncio/publish/mixed_via_post.yaml',
filter_query_parameters=['uuid', 'seqn', 'pnsdk'])
'tests/integrational/fixtures/asyncio/publish/mixed_via_post.json', serializer='pn_json',
filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'l_pub'])
@pytest.mark.asyncio
async def test_publish_mixed_via_post(event_loop):
pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between pnconf_copy and pnconf_env_copy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pnconf_env* uses keyset from environmental variables instead of those hardcoded. I'm slowly cleaning up what was in the repo for a while now

pubnub = PubNubAsyncio(pnconf_env_copy(), custom_event_loop=event_loop)
await asyncio.gather(
asyncio.ensure_future(assert_success_publish_post(pubnub, "hi")),
asyncio.ensure_future(assert_success_publish_post(pubnub, 5)),
Expand All @@ -92,24 +92,24 @@ async def test_publish_mixed_via_post(event_loop):


@pn_vcr.use_cassette(
'tests/integrational/fixtures/asyncio/publish/object_via_post.yaml',
'tests/integrational/fixtures/asyncio/publish/object_via_post.json', serializer='pn_json',
filter_query_parameters=['uuid', 'seqn', 'pnsdk'],
match_on=['method', 'scheme', 'host', 'port', 'path', 'query', 'object_in_body'])
@pytest.mark.asyncio
async def test_publish_object_via_post(event_loop):
pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop)
pubnub = PubNubAsyncio(pnconf_env_copy(), custom_event_loop=event_loop)
await asyncio.ensure_future(assert_success_publish_post(pubnub, {"name": "Alex", "online": True}))

await pubnub.stop()


@pn_vcr.use_cassette(
'tests/integrational/fixtures/asyncio/publish/mixed_via_get_encrypted.yaml',
filter_query_parameters=['uuid', 'seqn', 'pnsdk'])
'tests/integrational/fixtures/asyncio/publish/mixed_via_get_encrypted.json', serializer='pn_json',
filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'l_pub'])
@pytest.mark.asyncio
async def test_publish_mixed_via_get_encrypted(event_loop):
with patch("pubnub.crypto.PubNubCryptodome.get_initialization_vector", return_value="knightsofni12345"):
pubnub = PubNubAsyncio(pnconf_enc_copy(), custom_event_loop=event_loop)
pubnub = PubNubAsyncio(pnconf_enc_env_copy(), custom_event_loop=event_loop)
await asyncio.gather(
asyncio.ensure_future(assert_success_publish_get(pubnub, "hi")),
asyncio.ensure_future(assert_success_publish_get(pubnub, 5)),
Expand All @@ -120,28 +120,28 @@ async def test_publish_mixed_via_get_encrypted(event_loop):


@pn_vcr.use_cassette(
'tests/integrational/fixtures/asyncio/publish/object_via_get_encrypted.yaml',
'tests/integrational/fixtures/asyncio/publish/object_via_get_encrypted.json', serializer='pn_json',
filter_query_parameters=['uuid', 'seqn', 'pnsdk'],
match_on=['host', 'method', 'query']
)
@pytest.mark.asyncio
async def test_publish_object_via_get_encrypted(event_loop):
with patch("pubnub.crypto.PubNubCryptodome.get_initialization_vector", return_value="knightsofni12345"):
pubnub = PubNubAsyncio(pnconf_enc_copy(), custom_event_loop=event_loop)
pubnub = PubNubAsyncio(pnconf_enc_env_copy(), custom_event_loop=event_loop)
await asyncio.ensure_future(assert_success_publish_get(pubnub, {"name": "Alex", "online": True}))

await pubnub.stop()


@pn_vcr.use_cassette(
'tests/integrational/fixtures/asyncio/publish/mixed_via_post_encrypted.yaml',
filter_query_parameters=['uuid', 'seqn', 'pnsdk'],
'tests/integrational/fixtures/asyncio/publish/mixed_via_post_encrypted.json', serializer='pn_json',
filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'l_pub'],
match_on=['method', 'path', 'query', 'body']
)
@pytest.mark.asyncio
async def test_publish_mixed_via_post_encrypted(event_loop):
with patch("pubnub.crypto.PubNubCryptodome.get_initialization_vector", return_value="knightsofni12345"):
pubnub = PubNubAsyncio(pnconf_enc_copy(), custom_event_loop=event_loop)
pubnub = PubNubAsyncio(pnconf_enc_env_copy(), custom_event_loop=event_loop)
await asyncio.gather(
asyncio.ensure_future(assert_success_publish_post(pubnub, "hi")),
asyncio.ensure_future(assert_success_publish_post(pubnub, 5)),
Expand All @@ -153,38 +153,38 @@ async def test_publish_mixed_via_post_encrypted(event_loop):


@pn_vcr.use_cassette(
'tests/integrational/fixtures/asyncio/publish/object_via_post_encrypted.yaml',
'tests/integrational/fixtures/asyncio/publish/object_via_post_encrypted.json', serializer='pn_json',
filter_query_parameters=['uuid', 'seqn', 'pnsdk'],
match_on=['method', 'path', 'query']
)
@pytest.mark.asyncio
async def test_publish_object_via_post_encrypted(event_loop):
with patch("pubnub.crypto.PubNubCryptodome.get_initialization_vector", return_value="knightsofni12345"):
pubnub = PubNubAsyncio(pnconf_enc_copy(), custom_event_loop=event_loop)
pubnub = PubNubAsyncio(pnconf_enc_env_copy(), custom_event_loop=event_loop)
await asyncio.ensure_future(assert_success_publish_post(pubnub, {"name": "Alex", "online": True}))

await pubnub.stop()


@pytest.mark.asyncio
async def test_error_missing_message(event_loop):
pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop)
pubnub = PubNubAsyncio(pnconf_env_copy(), custom_event_loop=event_loop)
await assert_client_side_error(pubnub.publish().channel(ch).message(None), "Message missing")

await pubnub.stop()


@pytest.mark.asyncio
async def test_error_missing_channel(event_loop):
pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop)
pubnub = PubNubAsyncio(pnconf_env_copy(), custom_event_loop=event_loop)
await assert_client_side_error(pubnub.publish().channel("").message("hey"), "Channel missing")

await pubnub.stop()


@pytest.mark.asyncio
async def test_error_non_serializable(event_loop):
pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop)
pubnub = PubNubAsyncio(pnconf_env_copy(), custom_event_loop=event_loop)

def method():
pass
Expand All @@ -194,23 +194,23 @@ def method():


@pn_vcr.use_cassette(
'tests/integrational/fixtures/asyncio/publish/meta_object.yaml',
'tests/integrational/fixtures/asyncio/publish/meta_object.json', serializer='pn_json',
filter_query_parameters=['uuid', 'seqn', 'pnsdk'],
match_on=['host', 'method', 'path', 'meta_object_in_query'])
@pytest.mark.asyncio
async def test_publish_with_meta(event_loop):
pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop)
pubnub = PubNubAsyncio(pnconf_env_copy(), custom_event_loop=event_loop)

await assert_success_await(pubnub.publish().channel(ch).message("hey").meta({'a': 2, 'b': 'qwer'}))
await pubnub.stop()


@pn_vcr.use_cassette(
'tests/integrational/fixtures/asyncio/publish/do_not_store.yaml',
'tests/integrational/fixtures/asyncio/publish/do_not_store.json', serializer='pn_json',
filter_query_parameters=['uuid', 'seqn', 'pnsdk'])
@pytest.mark.asyncio
async def test_publish_do_not_store(event_loop):
pubnub = PubNubAsyncio(pnconf_copy(), custom_event_loop=event_loop)
pubnub = PubNubAsyncio(pnconf_env_copy(), custom_event_loop=event_loop)

await assert_success_await(pubnub.publish().channel(ch).message("hey").should_store(False))
await pubnub.stop()
Expand All @@ -225,11 +225,11 @@ async def assert_server_side_error_yield(pub, expected_err_msg):


@pn_vcr.use_cassette(
'tests/integrational/fixtures/asyncio/publish/invalid_key.yaml',
'tests/integrational/fixtures/asyncio/publish/invalid_key.json', serializer='pn_json',
filter_query_parameters=['uuid', 'seqn', 'pnsdk'])
@pytest.mark.asyncio
async def test_error_invalid_key(event_loop):
pnconf = pnconf_pam_copy()
pnconf = pnconf_pam_env_copy()

pubnub = PubNubAsyncio(pnconf, custom_event_loop=event_loop)

Expand All @@ -238,11 +238,11 @@ async def test_error_invalid_key(event_loop):


@pn_vcr.use_cassette(
'tests/integrational/fixtures/asyncio/publish/not_permitted.yaml',
'tests/integrational/fixtures/asyncio/publish/not_permitted.json', serializer='pn_json',
filter_query_parameters=['uuid', 'seqn', 'signature', 'timestamp', 'pnsdk'])
@pytest.mark.asyncio
async def test_not_permitted(event_loop):
pnconf = pnconf_pam_copy()
pnconf = pnconf_pam_env_copy()
pnconf.secret_key = None
pubnub = PubNubAsyncio(pnconf, custom_event_loop=event_loop)

Expand All @@ -252,7 +252,7 @@ async def test_not_permitted(event_loop):

@pytest.mark.asyncio
async def test_publish_super_admin_call(event_loop):
pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop)
pubnub = PubNubAsyncio(pnconf_pam_env_copy(), custom_event_loop=event_loop)

await pubnub.publish().channel(ch).message("hey").future()
await pubnub.publish().channel("f#!|oo.bar").message("hey^&#$").should_store(True).meta({
Expand Down
3 changes: 3 additions & 0 deletions tests/integrational/asyncio/test_subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ async def test_cg_join_leave():
assert prs_envelope.uuid == pubnub_listener.uuid
assert prs_envelope.channel == ch
assert prs_envelope.subscription == gr
await asyncio.sleep(2)

pubnub.add_listener(callback_messages)
pubnub.subscribe().channel_groups(gr).execute()
Expand All @@ -349,6 +350,7 @@ async def test_cg_join_leave():
assert prs_envelope.uuid == pubnub.uuid
assert prs_envelope.channel == ch
assert prs_envelope.subscription == gr
await asyncio.sleep(2)

pubnub.unsubscribe().channel_groups(gr).execute()

Expand All @@ -363,6 +365,7 @@ async def test_cg_join_leave():
assert prs_envelope.subscription == gr

pubnub_listener.unsubscribe().channel_groups(gr).execute()
await asyncio.sleep(2)

# with EE you don't have to wait for disconnect
if isinstance(pubnub._subscription_manager, AsyncioSubscriptionManager):
Expand Down
Loading
Loading