Skip to content

Unit testing nodes #302

Closed
Closed

Description

@Roh-codeur

I have been using this project and it's quite amazing!

Describe the solution you'd like
I would like to test out a combination of nodes. to do this, I need the ability to push individual messages to nodes and (sort of) invoke multiple cycles in the graph. for instance,

  1. Push a message to one of the nodes
  2. Assert the value in the output
  3. Push message onto one of the other nodes
  4. Assert the value in the output

Describe alternatives you've considered
I have been looking at the unit tests. I can see you create out ts in the test and push it to the node/graph and check the output in the end. I am able to do the same, however, do you think I can test out using the above workflow pls

sorry, if I missed something.

ta!

Activity

  1. AdamGlustein commented on Jun 27, 2024

    @AdamGlustein
    Collaborator

    I'm somewhat curious what you're using the above workflow for. Is it just so tests fail quicker if an output value is incorrect? You could always add assertions within the node itself before you return, but that will incur unnecessary overhead.

    As you alluded to, you can add any intermediate node's output to the result of csp.run by using csp.add_graph_output. Then you can extract all its values from the result dictionary and unit test against those values.

  2. Roh-codeur commented on Jun 27, 2024

    @Roh-codeur
    Author

    ahh, sorry, should have explained better. so, I use the above to do unit testing of each node by updating each input as a separate step and also to try out different scenarios(not unit testing, strictly speaking).
    consider the below pls:

    1. Say, a node calculates sum of numbers sent across 2 streams
    2. step 1: I would like to update just one stream
    3. Check the graph output
    4. step 2: I would like to update just second stream
    5. Check the graph output

    basically, control the graph cycles, if you will, to check intermediate outputs.

  3. AdamGlustein commented on Jun 27, 2024

    @AdamGlustein
    Collaborator

    Ok, thanks for more info. This is doable using csp.curve if you just set the times to be in a specific order. In your example:

    1. Let node N = add(A, B)
    2. step 1: stream A has event in a csp.curve at time t
    3. check output of N in node N before returning (could do this by asserting in the node, or printing if its debug)
    4. step 2: stream B has event in a csp.curve at time t+1
    5. same as 3

    You could also avoid any modifications to N by just checking all outputs at the end of csp.run. Does this answer your question?

  4. Roh-codeur commented on Jun 27, 2024

    @Roh-codeur
    Author

    ahh ok, I must be doing something wrong in my current tests then, I will give it another shot, thanks a lot mate. I will try again when I am home

  5. locked and limited conversation to collaborators on Jun 27, 2024
  6. converted this issue into a discussion #305 on Jun 27, 2024
  7. added
    tag: questionQuestions about use, potential features, or improvements
    on Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    tag: questionQuestions about use, potential features, or improvements

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions