Git Product home page Git Product logo

zeq's Introduction

zeq

A JavaScript library to help sequencing commands and event waiting.

Originally developed using node v8.11.2.

Tested with node v16.17.1 and v19.6.0. Some of the samples will not work with older node versions although zeq itself should work fine with old node versions.

zeq's People

Contributors

mayamatakeshi avatar mayamat avatar dependabot[bot] avatar

Watchers

James Cloos avatar  avatar

zeq's Issues

Occasional error when running regression tests

This happens sporadically:

13:55:09.053  All expected events received
13:55:09.053  wait (utils.mjs:333) finished
TypeError: this.resolve is not a function
    at Zester.process_event_during_wait (/usr/local/src/git/brastel/kue_job_queue/tests/node_modules/@mayama/zeq/src/index.js:147:22)
    at /usr/local/src/git/brastel/kue_job_queue/tests/node_modules/@mayama/zeq/src/index.js:301:22
    at new Promise (<anonymous>)
    at Zester.wait (/usr/local/src/git/brastel/kue_job_queue/tests/node_modules/@mayama/zeq/src/index.js:298:16)
    at create_job (file:///usr/local/src/git/brastel/kue_job_queue/tests/utils.mjs:333:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Module.create_job_and_wait_events (file:///usr/local/src/git/brastel/kue_job_queue/tests/utils.mjs:339:9)
    at async test (/usr/local/src/git/brastel/kue_job_queue/tests/functional/create_job_process_channel_rtp.ok.js:87:17)

An error occurred while executing create_job_process_channel_rtp.ok.js

The error happens at:

    process_event_during_wait(evt) {
        this.print_white("")
        this.print_white(`wait (${this.current_op_line}) got event:`)
        this.print_white(zutil.prettyPrint(evt, 1))

        var temp = this.expected_events.slice() // copy array
        var matching_errors = []

        var matched = false

        for(var i=0 ; i<temp.length ; ++i) {
            try {
                this.print_white("")
                this.print_white(`Trying match against expected_events[${i}]:`)
                this.print_white(zutil.prettyPrint(temp[i], 1))

                if(this.match(temp[i], evt, i)) {
                    this.print_white(`Match successful`)

                    this.set_store_vars(this.dict)
                    this.print_white("")
                    this.print_green(`wait (${this.current_op_line}) got expected event:`)
                    this.print_white(zutil.prettyPrint(evt, 1))

                    this.expected_events.splice(i, 1)
                    matched = true
                    break
                }
            } catch(e) {
                if(e instanceof matching.MatchingError) {
                    this.print_white(`No match: ${e.path}: ${e.reason}`)
                    matching_errors[i] = e
                } else {
                    this.print_red(e)
                    clearTimeout(this.timer_id)
                    this.timer_id = null
                    this.reject(e)
                    return
                }
            }
        }

        if(matched) {
            if(this.expected_events.length == 0) {
                this.print_white("All expected events received")
                this.print_green(`wait (${this.current_op_line}) finished`)

                this.current_op_name = null

                clearTimeout(this.timer_id)
                this.timer_id = null
                this.resolve() //THE PROBLEM HAPPENS HERE
            }

zeq version: "@mayama/zeq": "^4.1.17"

We will investigate this after we do #3 as it will make it easier to debug.

Permit to pass store when creating Zeq instance

Currently we create a Zeq instance this way:

var z = new Zeq()

We should be able to do it like this:

var z = new Zeq({store: {a: 1, b: 2}})

This is to permit to preset some data.
Also, it should be possible to do:

var z = new Zeq(null)

and this will instruct Zeq not use a store but instead check and set global variables.
(this will simplify writing tests but will prevent the use of the test function in load tests or other situations where there would be multiple instances of the test running)

Code for reference:

> myfu = (x) => { if(x === undefined) { return 'undefined'} else if(x === null) {return 'null'} else { return x} }
[Function: myfu]
> myfu()
'undefined'
> myfu(undefined)
'undefined'
> myfu(null)
'null'
> myfu({a:1})
{ a: 1 }
> 

What matters is that we can differentiate between undefined (normal behavior, creating internal store) and null (update global variables).

Add support for data-matching pop operation

Currently pop does't work because when we handle the zeq store to the matcher, we pass an empty dict to it, then if the match succeeds we set the variables present in the dict to the store (and fails if they are already set).

So we need to change the implementation to deep copy the store when passing the dict to the matcher.
Then if the match succeeds, copy the dict back to the store.

Obs: the push operation works (see for example: https://github.com/MayamaTakeshi/sip-lab/blob/master/samples/100_calls.js). However I think this is not correct and works due to a specific usage scenario in the test.

Simplify samples to avoid bad habits

For example, in samples/axios2.mjs we have:

    await z.wait([
        {
            event: 'https_res',
            res: m.collect('client_res'),
        },
    ], 1000)

    assert(z.store.client_res.status == 200)
    assert(z.store.client_res.data.status == 0)

This can be done more clearer this way:

    await z.wait([
        {
            event: 'https_res',
            res: {
                status: 200,
                data: {
                    status: 0
                }
            }
        },
    ], 1000)

Add support for event simplification

This is to permit to minimize output when dumping events by omitting irrelevant data.
So for example the dump of an http req object could contain just the url, headers and body.
The objects to be simplified might be identified using instanceof but we could permit to pass a function.
We will provide default dumpers and we will include one for http req as we need to realize the field headers (see #4).

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.