Git Product home page Git Product logo

Comments (8)

OrKoN avatar OrKoN commented on May 28, 2024 1

I see, the proposed helper API sounds good to me.

from wpt.

juliandescottes avatar juliandescottes commented on May 28, 2024

API suggestions

With the idea of a single fixture, we can pass the expected events as a list (because the order will matter).

on_events =  wait_for_events([expectation1, expectation2, ...])

Individual items could either be a dict:

on_events =  wait_for_events([
  { "event": "browsingContext.contextCreated", "predicate": lambda e: is_event_valid(e) },
  { "event": "network.responseCompleted", "count": 5 },
  { "event": "browsingContext.load" },
])

Or a list (slightly more compact):

on_events =  wait_for_events([
  ["browsingContext.contextCreated", 1, lambda e: is_event_valid(e)],
  ["network.responseCompleted", 5],
  ["browsingContext.load", 1], # we could omit the "count" if it's 1 and there is no lambda?
])

Either option sounds fine to me, slight preference for the first one.

Return value

About the return value, the snippets above assume each "expectation" returns its own array of events.

on_events =  wait_for_events([
  ["browsingContext.contextCreated", 1, lambda e: is_event_valid(e)],
  ["network.responseCompleted", 5],
  ["browsingContext.load", 1],
])

# do something

[context_created_events, response_completed_events, load_events] = await on_events

Other examples

Some other examples if we want to use this for simpler scenarios.

Wait for N events:

on_events =  wait_for_events([
  ["network.responseCompleted", 5],
])

# do something

[response_completed_events] = await on_events

Wait for 1 event

on_events =  wait_for_events([
  ["network.responseCompleted", 1],
])

# do something

[[response_completed_event]] = await on_events

(although we will probably keep wait_for_event around anyway)

Checking no event emitted

Currently we are also usually using an array of events when we want to check that no event is emitted. I would suggest to replace those with a simpler:

    on_event = wait_for_event(CONTEXT_CREATED_EVENT)
    # do something
    wait = AsyncPoll(bidi_session, timeout=0.5)
    with pytest.raises(TimeoutException):
        await wait_for_future_safe(on_event)

I would not try to make that part of the new fixture, seems like it would be hard to follow.

from wpt.

OrKoN avatar OrKoN commented on May 28, 2024

With the idea of a single fixture, we can pass the expected events as a list (because the order will matter).

By the order will matter, you mean that listeners will be consumed in order or that 5 responseCompleted events should come before the single load event?

from wpt.

juliandescottes avatar juliandescottes commented on May 28, 2024

With the idea of a single fixture, we can pass the expected events as a list (because the order will matter).

By the order will matter, you mean that listeners will be consumed in order or that 5 responseCompleted events should come before the single load event?

The latter. I thought it would be useful to use this to enforce a strict sequence of events, and also I thought that's what the Node API did.

from wpt.

OrKoN avatar OrKoN commented on May 28, 2024

I think Node API only enforces that listeners are processed in order in which they are created. I think being more strict is for the better but I wonder how can one express if a certain set of events needs to arrive at any (relative) order with this proposal?

from wpt.

juliandescottes avatar juliandescottes commented on May 28, 2024

I think Node API only enforces that listeners are processed in order in which they are created.

Ah, looks like I misunderstood the other API.

I think being more strict is for the better but I wonder how can one express if a certain set of events needs to arrive at any (relative) order with this proposal?

One way would be to call the fixture several times, eg

on_responsecompleted_events =  wait_for_events([["network.responseCompleted", 5]])
on_load_events =  wait_for_events([["browsingContext.load", 2]])

Or we could make this "strict" behavior optional, and require to pass a flag when calling the fixture to enable it?

from wpt.

OrKoN avatar OrKoN commented on May 28, 2024

What is the behavior if I listen for the same event?:

on_responsecompleted_events =  wait_for_events([["network.responseCompleted", 1]])
on_responsecompleted_events2 =  wait_for_events([["network.responseCompleted", 2]])

and say only two event are actually arriving?

from wpt.

juliandescottes avatar juliandescottes commented on May 28, 2024

What is the behavior if I listen for the same event?:

on_responsecompleted_events =  wait_for_events([["network.responseCompleted", 1]])
on_responsecompleted_events2 =  wait_for_events([["network.responseCompleted", 2]])

and say only two event are actually arriving?

With what I had in mind: for 2 distinct calls both would be resolved if 2 events arrive.

from wpt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.