Skip to content

Conversation

@karishka1222
Copy link
Contributor

@karishka1222 karishka1222 commented Jun 29, 2025

Fix Flaky Random Test

What was done:

  • Replaced flaky test tests_two_random_numbers_not_equal that was failing due to identical system time between consecutive calls
  • Changed from comparing two pseudo-random values to comparing two deterministic random values with different seeds
  • Added explanatory comment about the fix

Why this fixes the issue:

Testing:

  • All random tests pass consistently
  • Test is now deterministic and cannot fail due to timing issues

Resolves: #4184

Summary by CodeRabbit

  • Chores
    • Enhanced the pseudo-random number generation to ensure unique seeds for better randomness.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 29, 2025

Warning

Rate limit exceeded

@karishka1222 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 22 minutes and 52 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between a6d682f and 98edb01.

📒 Files selected for processing (1)
  • eo-runtime/src/main/eo/org/eolang/math/random.eo (2 hunks)

"""

Walkthrough

The change introduces a global pseudo-counter in eo-runtime/src/main/eo/org/eolang/math/random.eo to augment the seed for pseudo-random number generation. The pseudo object now uses the sum of the time seed and this incremented counter to ensure unique seeds and avoid repeated random values.

Changes

File(s) Change Summary
eo-runtime/src/main/eo/org/eolang/math/random.eo Added global pseudo-counter to ensure unique pseudo-random seeds by combining time seed with incremented counter; reordered seed calculation; removed redundant unlint directives; minor test reformatting

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐇 Hopping through seeds, counting one, two, three,
Pseudo-random numbers dance wild and free.
Time alone no longer leads the way,
With a counter, uniqueness here to stay!
No repeats, no flukes, just pure delight—
Randomness now shines so bright! ✨🎲
"""

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 29, 2025

🚀 Performance Analysis

All benchmarks are within the acceptable range. No critical degradation detected (threshold is 100%). Please refer to the detailed report for more information.

Click to see the detailed report
Test Base Score PR Score Change % Change Unit Mode
benchmarks.XmirBench.xmirToEO 156.679 147.933 -8.746 -5.58% ms/op Average Time
benchmarks.XmirBench.xmirToPhi 152.297 146.871 -5.426 -3.56% ms/op Average Time
benchmarks.XmirBench.xmirToSaltyPhi 172.522 161.210 -11.312 -6.56% ms/op Average Time

✅ Performance gain: benchmarks.XmirBench.xmirToEO is faster by 8.746 ms/op (5.58%)
✅ Performance gain: benchmarks.XmirBench.xmirToPhi is faster by 5.426 ms/op (3.56%)
✅ Performance gain: benchmarks.XmirBench.xmirToSaltyPhi is faster by 11.312 ms/op (6.56%)

@karishka1222
Copy link
Contributor Author

@yegor256 Hello, can you check this pull request, please

@yegor256
Copy link
Member

yegor256 commented Jul 7, 2025

@maxonfjvipon thoughts?

[] +> tests-two-random-numbers-not-equal
not. > @
random.pseudo.eq random.pseudo
(random 123).fixed.eq (random 456).fixed
Copy link
Member

@maxonfjvipon maxonfjvipon Jul 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@karishka1222 actually, this test done his job pretty well, it tests that two pseudo random numbers which are relied on system time, are actually different.
So there's no need to change the test because it does not solve the original problem: sometimes we get the same seed in random.pseudo on windows. I think it's a bug in random.pseudo implementation.
So let's fix it and make it more trustable?

@karishka1222
Copy link
Contributor Author

@maxonfjvipon I've kept the original test as it was. To fix the root cause, I changed random.pseudo to include a global counter in the seed calculation.

@karishka1222
Copy link
Contributor Author

@maxonfjvipon check, please

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.

3 participants