Skip to content

test that yield is given number of seconds#6

Merged
ioquatix merged 1 commit into
ruby:masterfrom
jjb:test-for-block-param
Sep 27, 2021
Merged

test that yield is given number of seconds#6
ioquatix merged 1 commit into
ruby:masterfrom
jjb:test-for-block-param

Conversation

@jjb

@jjb jjb commented Sep 24, 2021

Copy link
Copy Markdown
Contributor

Nothing currently covers this behavior

@ioquatix

Copy link
Copy Markdown
Member

This looks good to me but I feel a little bit odd about using a string. But it also works pretty well… what do you think?

@jjb

jjb commented Sep 26, 2021

Copy link
Copy Markdown
Contributor Author

My goal was to do something "realistic" which does something with the value, to test that the return value is what the block returns and also that the block has access to the param.

If we don't use a string, what alternative do you have in mind? one of these?

    assert_equal 5, Timeout.timeout(5){|s| s }
    assert_equal 6, Timeout.timeout(5){|s| s+1 }

@ioquatix

Copy link
Copy Markdown
Member

I would say there are two tests:

  • That the time is provided to the block as an argument.
  • That the value of the block is returned.

The biggest issue I see with the string formatting is time precision, but as long as we use an integer, it would be okay? But I'm not sure we can guarantee the value of the timeout argument? In the future we might want a more precise measurement of time than just the numeric value.

@jjb

jjb commented Sep 26, 2021

Copy link
Copy Markdown
Contributor Author

ah, so you are saying that involving the string interpolation makes the test brittle, because one day the code might, say, run to_f on s, and then the string will be "5.0 seconds" and the test will erroneously break?

what do you think of one of these?

    assert_equal 5, Timeout.timeout(5){|s| s }
    assert_equal 6, Timeout.timeout(5){|s| s+1 }
    assert_equal [5, :ok], Timeout.timeout(5){|s| [s, :ok] }
    x = rand(1..10); assert_equal x, Timeout.timeout(x){|s| s }

although... those might all have the same problem... depending on if the test environment does a flexible equals 5==5.0

@ioquatix

Copy link
Copy Markdown
Member

I think as long as we consider the issue, I'm fine with whatever you ultimately propose.

@jjb jjb force-pushed the test-for-block-param branch from e7b232a to 939a9f5 Compare September 27, 2021 10:28
@jjb

jjb commented Sep 27, 2021

Copy link
Copy Markdown
Contributor Author

Okay, I went with the array

@jjb

jjb commented Sep 27, 2021

Copy link
Copy Markdown
Contributor Author

I don't know why CI isn't running... a rebase and another push triggered it now

@jjb jjb force-pushed the test-for-block-param branch from 939a9f5 to d62d22d Compare September 27, 2021 12:11
@ioquatix ioquatix merged commit ec5a614 into ruby:master Sep 27, 2021
@jjb jjb deleted the test-for-block-param branch September 27, 2021 21:17
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

Successfully merging this pull request may close these issues.

2 participants