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

Add missing sessions test #156

Merged
merged 3 commits into from
Dec 8, 2019
Merged

Conversation

Zsailer
Copy link
Member

@Zsailer Zsailer commented Dec 7, 2019

@kevin-bates and @echarles Here are the missing sessions tests left out of #152.

Copy link
Member

@kevin-bates kevin-bates left a comment

Choose a reason for hiding this comment

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

@Zsailer - thanks for getting this in so quickly. I just had a question and a comment.

assert got == new_session

# Need to find a better solution to this.
await session_client.cleanup()
Copy link
Member

Choose a reason for hiding this comment

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

Can we add these cleanup calls to the fixture, after the yield and prior to the dir removal?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I had tried to get this to work, but async-ness of this call makes it challenging. I couldn’t find a way to both yield in the session client fixture and use this asynchronous cleanup method. Do you how to do this?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I see what you mean. I just tried a few things to no avail. There are ways to create async fixtures but I'm not having much luck. Let's revisit since this is more of a test impl issue.

Copy link
Member

Choose a reason for hiding this comment

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

I'm currently having success with this (using pytest.yield_fixture and run_sync). File attached below ...

def run_sync(coro_method):
    return asyncio.get_event_loop().run_until_complete(coro_method)


@pytest.yield_fixture
def session_client(root_dir, fetch):
    subdir = root_dir.joinpath('foo')
    subdir.mkdir()

    # Write a notebook to subdir.
    nb = new_notebook()
    nb_str = writes(nb, version=4)
    nbpath = subdir.joinpath('nb1.ipynb')
    nbpath.write_text(nb_str, encoding='utf-8')

    # Yield a session client
    client = SessionClient(fetch)
    yield client

    # Invoke async method on separate loop
    run_sync(client.cleanup())

    # Remove subdir
    shutil.rmtree(str(subdir), ignore_errors=True)

test_api.py.txt

Copy link
Member

Choose a reason for hiding this comment

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

Warning - I'm not convinced this will work on 3.5 and I'd prefer to understand things better (like why does yield_fixture change things).

tests/services/sessions/test_api.py Show resolved Hide resolved
@echarles
Copy link
Member

echarles commented Dec 7, 2019

Test on my mac and tests passed. We have 1 more warning.

LGTM - I guess we can merge when Zach will have pushed the change he was not able during his fly. We can also come back on the async fixture later.

Copy link
Member

@kevin-bates kevin-bates left a comment

Choose a reason for hiding this comment

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

OK. Let's circle back regarding the session teardown issue once 0.2 is done.

@kevin-bates kevin-bates merged commit e1b4ce4 into jupyter-server:master Dec 8, 2019
@Zsailer
Copy link
Member Author

Zsailer commented Dec 9, 2019

Thanks, @kevin-bates!

@Zsailer Zsailer deleted the sessions-tests branch January 10, 2020 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants