DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Implementing BCDR Testing in Your Software Development Lifecycle
  • Advancements in Mobile App Testing: Harnessing AI's Potential
  • Test Automation Success With Measurable Metrics
  • The Illusion of Safety: Thoughts on 100% Test Coverage

Trending

  • Securing Your Applications With Spring Security
  • Extracting Maximum Value From Logs
  • Build Quicker With Zipper: Building a Ping Pong Ranking App Using TypeScript Functions
  • The API-Centric Revolution: Decoding Data Integration in the Age of Microservices and Cloud Computing

The Occasionally Failing Test

Very occasionally, this test would fail, and it would be nearly impossible to figure out why. Can you find the not-so-obvious error?

Oren Eini user avatar by
Oren Eini
·
Apr. 28, 17 · Opinion
Like (1)
Save
Tweet
Share
2.93K Views

Join the DZone community and get the full member experience.

Join For Free

This piece of code is part of a test that runs a scenario and checks that the appropriate errors are logged. Very occasionally, this test would fail, and it would be nearly impossible to figure out why.

I’ve extracted the offending code from the test. ReadFromWebSocket returns a Task<string>, since that isn’t obvious from the code. Do you see the error?

image

Think about it. What is this doing?

This is reading from a socket, and there is absolutely no guarantee about the amount of data that will go over the wire at any particular point. Because this test assumes that the entire string will be read in a single call from the socket, if the expected value we are looking is actually going to be returned in two calls, we’ll miss it — and this will never return, leading to sadness and worry everywhere — at least everywhere that we care about our tests!

The fix was to remember the previous values and compare to all the data read from the socket, not to just the values that were returned in the last call.

Testing

Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Implementing BCDR Testing in Your Software Development Lifecycle
  • Advancements in Mobile App Testing: Harnessing AI's Potential
  • Test Automation Success With Measurable Metrics
  • The Illusion of Safety: Thoughts on 100% Test Coverage

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: