Closed Bug 1425947 Opened 6 years ago Closed 6 years ago

No finalizers get run for sessions created with the `new_session` fixture

Categories

(Testing :: geckodriver, enhancement)

Version 3
enhancement
Not set
major

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: whimboo, Assigned: whimboo)

References

Details

Attachments

(2 files)

As noticed on bug 1403923 none of the finalizers which usually get added to a session is getting run if the `new_session` fixture is used. It only works for test methods which use the `session` fixture.

Works:
======

def test_foobar(session):
    assert 1 == 1


Fails:
======

def test_foobar(new_session, add_browser_capabilites):
    assert 1 == 1


This can cause lots of trouble for following tests, at least until the browser gets restarted.
So we do not add any finalizer inside of `new_session`:

https://dxr.mozilla.org/mozilla-central/source/testing/web-platform/tests/webdriver/tests/support/fixtures.py#176-202

Instead we call `end()` twice! The first time directly while creating the session, which basically reverts the newly created session to the global one, and then once again at the end of the test.

Maybe I miss something but I don't think that we ever should call `end()` directly here, but only through the added finalizer. Doesn't it make all of those tests currently invalid?

James, I would appreciate your feedback here. Thanks.
Flags: needinfo?(james)
Ok, calling `end()` directly is actually used to end a former session as started by a previous test. So it would be important to keep.
Flags: needinfo?(james)
Assignee: nobody → hskupin
Status: NEW → ASSIGNED
Attachment #8937688 - Flags: review?(james)
Attachment #8937688 - Flags: review?(ato)
Attachment #8937689 - Flags: review?(james)
Attachment #8937689 - Flags: review?(ato)
Comment on attachment 8937689 [details]
Bug 1425947 - Expose session capabilities in 'new_session' fixture.

https://reviewboard.mozilla.org/r/208396/#review214162
Attachment #8937689 - Flags: review?(james) → review+
Comment on attachment 8937689 [details]
Bug 1425947 - Expose session capabilities in 'new_session' fixture.

https://reviewboard.mozilla.org/r/208396/#review214166
Attachment #8937689 - Flags: review?(ato) → review+
Comment on attachment 8937688 [details]
Bug 1425947 - Run session finalizers also for new_session fixture.

https://reviewboard.mozilla.org/r/208394/#review214164

::: testing/web-platform/tests/webdriver/tests/support/fixtures.py:49
(Diff revision 1)
>  
>  
>  @ignore_exceptions
> -def _dismiss_user_prompts(session):
> -    """Dismisses any open user prompts in windows."""
> -    current_window = session.window_handle
> +def _dismiss_user_prompts():
> +    """Dismiss any open user prompts in windows."""
> +    global _current_session

`global` is for things that you write to. Since the varaible isn't being rebound it's not appropriate here.

::: testing/web-platform/tests/webdriver/tests/support/fixtures.py:187
(Diff revision 1)
>      except webdriver.error.SessionNotCreatedException:
>          if not _current_session.session_id:
>              raise
>  
> -    # finalisers are popped off a stack,
> -    # making their ordering reverse
> +    # finalisers are popped off a stack, making their ordering reverse
> +    request.addfinalizer(_switch_to_top_level_browsing_context)

This seems all wrong. These should run after each test, not after each session? Presumably the browser is shut after each session anyway, so what  does this achieve?
Attachment #8937688 - Flags: review?(james) → review-
Comment on attachment 8937688 [details]
Bug 1425947 - Run session finalizers also for new_session fixture.

https://reviewboard.mozilla.org/r/208394/#review214174

I’m puzzled by the changes to make a number of these fixtures and
helpers not rely on the ‘session’ fixture but on _current_session.
This will presumably mean we can no longer guarantee a session will
be available to the next test that uses the fixture?

::: testing/web-platform/tests/webdriver/tests/support/fixtures.py:34
(Diff revision 1)
> -def _ensure_valid_window(session):
> -    """If current window is not open anymore, ensure to have a valid
> -    one selected.
> +def _ensure_valid_window():
> +    """Ensure to have a valid window selected if current one has been closed."""
> +    global _current_session
> +    if not _current_session:
> +        return

The reason this function takes the ‘session’ fixture is so that the
harness can guarantee there is always a window.  This means a new
session will be created if there isn’t one.

This changes it to fail silently if there is no session.
Attachment #8937688 - Flags: review?(ato) → review-
Comment on attachment 8937688 [details]
Bug 1425947 - Run session finalizers also for new_session fixture.

https://reviewboard.mozilla.org/r/208394/#review214174

The next test will have a `session` fixture itself, and as such would create a new session.

> The reason this function takes the ‘session’ fixture is so that the
> harness can guarantee there is always a window.  This means a new
> session will be created if there isn’t one.
> 
> This changes it to fail silently if there is no session.

Ok, I see. I'm new to fixtures so that wasn't obviously clear to me. But then all the calls like `request.addfinalizer(lambda: _dismiss_user_prompts(_current_session))` are wrong and should not have the `_current_session` as argument because it gets generated by the session fixture, right?
Comment on attachment 8937688 [details]
Bug 1425947 - Run session finalizers also for new_session fixture.

https://reviewboard.mozilla.org/r/208394/#review214164

> This seems all wrong. These should run after each test, not after each session? Presumably the browser is shut after each session anyway, so what  does this achieve?

As we have seen on bug 1403923 the left over alerts can cause trouble during shutdown. Maybe other kind of things which we usually clean-up with the finalizers for normal sessions could cause similiar behavior. Cleaning up everything what has been opened for the current session (whether if it has been created via `session` or `new_session`) would ensure a shutdown will be successful. Or are you saying that we should not care about the clean-up for `new_session` and live with possible timeouts during shutdown?
I would like to know how the intended behavior for a temporary session should be during cleanup. Don't we want to do anything and leave various windows, alerts etc open, or clearly clean all those up before shutting down the browser?

Catching a shutdown issue with Firefox like in this case is good, but it means that unexpected behavior can appear during the wdspec tests.
Flags: needinfo?(james)
Flags: needinfo?(dburns)
Flags: needinfo?(ato)
I feel like anything that interferes with session shutdown is a pretty serious bug and should be prioritized as such, rather than adding workarounds in the test harness to let us get away with bad behaviour.
Flags: needinfo?(james)
We also discussed this topic in our chitchat and we agreed on marking this as wontfix.
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Flags: needinfo?(dburns)
Flags: needinfo?(ato)
Resolution: --- → WONTFIX
Blocks: 1431058
No longer blocks: 1431058
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: