Skip to content

Conversation

@nijeesh-stream
Copy link
Contributor

@nijeesh-stream nijeesh-stream commented Jul 1, 2025

Submit a pull request

CLA

  • I have signed the Stream CLA (required).
  • The code changes follow best practices
  • Code changes are tested (add some information if not applicable)

Description of the pull request

The test suite was experiencing flakiness due to hardcoded user IDs and channel IDs that could cause conflicts between test runs, especially when running tests in parallel or consecutively without proper cleanup.

Changes Made

🔧 Dynamic User ID Generation

  • Before: Used hardcoded user IDs like 'frodo-baggins', 'sam-gamgee', 'gandalf', 'legolas'
  • After: Generate unique user IDs using SecureRandom.uuid for each test run
  • Impact: Eliminates user ID conflicts between test runs

🏗️ Dynamic Channel ID Generation

  • Before: Used hardcoded channel ID 'fellowship-of-the-ring'
  • After: Generate unique channel IDs using "fellowship-of-the-ring-chat-#{SecureRandom.alphanumeric(20)}" pattern
  • Impact: Prevents channel conflicts and ensures proper test isolation

🧹 Improved Test Cleanup

  • Added proper channel cleanup in after(:all) hook with @channel.delete
  • Enhanced user deletion to include both random users and fellowship users
  • Updated user deletion logic to handle all created users consistently
  • Impact: Ensures no leftover data affects subsequent test runs

📝 Consistent Reference Management

  • Updated all hardcoded string references to use dynamically generated IDs stored in instance variables
  • Fixed user creation logic to be more consistent and trackable
  • Updated search and query tests to use dynamic user references
  • Impact: Ensures all test operations use the correct dynamic identifiers

🎯 Specific Test Improvements

  • Reminders tests: Improved setup to use existing test infrastructure instead of creating separate client/channel
  • Export user test: Updated to use dynamic @gandalf variable instead of hardcoded 'gandalf'
  • Search tests: Updated to use dynamic user references for better isolation

Files Modified

  • spec/client_spec.rb - Main client test suite with comprehensive flakiness fixes
  • spec/moderation_spec.rb - Moderation test suite with similar isolation improvements

@nijeesh-stream nijeesh-stream marked this pull request as ready for review July 2, 2025 08:15
@nijeesh-stream nijeesh-stream changed the title [NOT READY TO REVIEW] isloated tests isloated tests Jul 2, 2025
@nijeesh-stream nijeesh-stream merged commit fd85415 into master Jul 2, 2025
7 of 13 checks passed
@nijeesh-stream nijeesh-stream deleted the fix-flakyness branch July 2, 2025 08:41
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