# Write testable code by writing generic code

DevFeed: [Write testable code by writing generic code](<https://devfeed.tech/articles/write-testable-code-by-writing-generic-code-21978.md>)

Original publisher: [Read original article](<https://blog.nelhage.com/post/write-testable-code-by-writing-generic-code/>)

Author: Nelson Elhage

Published: 2020-03-12T01:30:17Z

Content type: article

Language: en

Sources: [Nelson Elhage](<https://devfeed.tech/sources/nelson-elhage.md>)

Topics: [Testing](<https://devfeed.tech/topics/testing.md>), [Amazon S3](<https://devfeed.tech/topics/amazon-s3.md>), [Code](<https://devfeed.tech/topics/code.md>), [Software Engineering](<https://devfeed.tech/topics/software-engineering.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [s3](<https://devfeed.tech/tags/s3.md>), [software](<https://devfeed.tech/tags/software.md>), [software-testing](<https://devfeed.tech/tags/software-testing.md>), [testing](<https://devfeed.tech/tags/testing.md>)

## AI overview

The article examines how to make difficult error-handling behavior easier to test by generalizing a specific S3 connection-reset problem into a generic retryable stream abstraction. The supplied text describes restarting reads from the current byte offset using S3 range requests.

## Source excerpt

Alex Gaynor recently asked this question in an IRC channel I hang out in (a channel which contains several software engineers nearly as obsessed with software testing as I am): uhh, so I'm writing some code to handle an econnreset... how do I test this? This is a good question! Testing ECONNRESET is one of those fiddly problems that exists at the interface between systems -- in his case, with S3, not even a system under his control -- that can be infuriatingly tricky to reproduce and test.