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

ramda.js not working #339

Closed
ragnarlonn opened this issue Oct 16, 2017 · 6 comments
Closed

ramda.js not working #339

ragnarlonn opened this issue Oct 16, 2017 · 6 comments

Comments

@ragnarlonn
Copy link

ragnarlonn commented Oct 16, 2017

The below, reported by askierniewski@slack, happens when the script further down is run:

ERRO[0009] TypeError: Cannot read property 'find' of undefined========]      700ms / 0s
	at cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js:1:3486(51)
	at e (cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js:1:1069(76))
	at /Users/ragnarlonn/src/go/src/github.com/loadimpact/k6/askierniewski.js:29:24(12)
	at native
	at /Users/ragnarlonn/src/go/src/github.com/loadimpact/k6/askierniewski.js:27:17(32)

The script:

import * as R from "cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"
import {group, sleep, check} from "k6"
import http from "k6/http"

const parseBody = res => {
  let res2 = R.clone(res) // just to be sure that I'm not working on original object
  if (R.is(String(res.body) && !R.isEmpty(res.body) && R.isEmpty(res.error))) {
    try { // Remove try catch block to get "SyntaxError: EOF" on valid JSON
      res.body = JSON.parse(res.body)
    } catch (err) {
      // "SyntaxError: EOF" error is thrown as part of execution teardown
      console.error('JSON.parse ERROR!') // Adding try catch removes SyntaxError but it wont log this line ?!
    }
  }
  return res2
}

export default function() {

  const productId = 1
 
  let res = http.get("https://api.dev.peachworks.com/v1/products")

  const products = parseBody(res).results
  sleep(0.1)

  group("xxx", function() {

    const setup2 = R.find(R.propEq('id', productId), products)
    sleep(0.1)

    group("yyy", function() {

      const setup3 = R.find(R.propEq('id', productId), products)
      sleep(0.1)
    })

  })
}
@liclac
Copy link
Contributor

liclac commented Oct 16, 2017

What precisely happens when you do this, and what did you expect would happen?

@ragnarlonn
Copy link
Author

Precisely that error message happens. I have no idea what should happen though :) Looking briefly at the ramda.js docs, it seems R.clone() will make a deep copy of the obj, and then R.find() "returns the first element of the list which matches the predicate". Hmm, a list?

@ppcano
Copy link
Contributor

ppcano commented Oct 16, 2017

wrong reply

@ppcano
Copy link
Contributor

ppcano commented Oct 16, 2017

Closing it because the problem looks a bug in the parseBody function.

export default function() {

  const productId = 1

  let res = http.get("https://api.dev.peachworks.com/v1/products")

  const products = JSON.parse(res.body).results
  sleep(0.1)


  group("xxx", function() {

    const product = R.find(R.propEq('id', productId), products)
    check(product, {
      "product 1 found": () => product && product.id === productId
    });
    sleep(0.1)

    group("yyy", function() {

      const product2 = R.find(R.propEq('id', productId), products)
      check(product2, {
        "product 2 found": () => product2 && product2.id === productId
      });
      sleep(0.1)
    })

  })
}

Please, open a stackoverflow question for this type of questions.

https://github.com/loadimpact/k6#need-help-or-want-to-contribute

@ppcano ppcano closed this as completed Oct 16, 2017
@AdrianSkierniewski
Copy link

@liclac @ragnarlonn @ppcano Please don't suggest that clone call it's irrelevant (probably whole ramda) to this issue. Here is a more simplistic version with a different error.

ERRO[0021] SyntaxError: EOF==========================================] -- / --
	at parse (native)
	at /scripts/k6/tests/panera/example.js:26:29(19)

This error is probably related to that ramda issue later and it looks like the root cause of it is related to usage of stages. Errors disappear after removing stages.

import * as R from "cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"
import {group, sleep, check} from "k6"
import http from "k6/http"

export let options = {
  stages: [
    {duration: "20s", target: 5},
    {duration: "10s"},
    {duration: "50s", target: 20},
    {duration: "10s"},
    {duration: "50s", target: 40},
    {duration: "10s"},
    {duration: "50s", target: 60},
    {duration: "100s"},
    {duration: "30s", target: 40},
    {duration: "20s"},
  ]
}

export default function() {

  const productId = 1
  // Get all locations to reuse them in tests
  let res = http.get("https://api.dev.peachworks.com/v1/products")

  const products = JSON.parse(res.body).results
  sleep(0.1)

  group("xxx", function() {

    const setup2 = R.find(R.propEq('id', productId), products)
    sleep(0.1)

    group("yyy", function() {

      const setup3 = R.find(R.propEq('id', productId), products)
      sleep(0.1)
    })

  })
}

Should I create a separate issue for this?

@ppcano
Copy link
Contributor

ppcano commented Oct 16, 2017

I reproduced this case in the following gist.

The problem with the above script is that wrong data will be passed to the ramda library when the response fails.

It looks to exist a bug that reports wrongly checks when using stages. This possible bug has confused the issue investigation. I will try to reproduce it again and will create a new issue.

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

No branches or pull requests

4 participants