Testing Tips: Avoid sleep in tests

Hi 👋, In this article I wanna show a testing tip that I’ve recently learned myself by reading Software Engineering at Google: Lessons Learned from Programming Over Time. The technique improved the way I write unit tests. When I’m writing bigger unit tests, I have execute something in the background, like for example publishing a message to a message broker, wait for the message to be published and then consume it to test that what I published is correct. ...

July 12, 2022 · 4 min · Denis Nuțiu

The Go *Options pattern

Introduction Hello everyone! 👋 In this article I’ll present you the options pattern in Golang. The pattern is useful when you want to create a function that takes different parameters as an option. Code Study: Building a rocket The following code defines a Rocket struct with 3 fields and a NewRocket function which builds an instance of the Rocket. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // Rocket models a rocket. type Rocket struct { name string nose Nose fuelCapacity int } // NewRocket returns a new rocket instance. func NewRocket(name string, nose Nose, fuelCapacity int) Rocket { return Rocket{ name: name, nose: nose, fuelCapacity: fuelCapacity, } } To use the NewRocket function one would have to write something like this: ...

November 26, 2024 · 4 min · Denis Nutiu

The Hash Set

Introduction A hash set is a data structure that allows storing elements inside a set using a hash function. The set is a data structure that offers efficient access to its elements and does not allow duplicates. The uniqueness of an element in the hash set is determined by the hash function, in this implementation hash collisions are not handled. If the hash of “a” is 123 and the hash of “b” is 123 as well then we consider “a” and “b” to have a hash collision and if “a” is already present in the set adding “b” has no effect. ...

September 15, 2024 · 4 min · Denis Nutiu

Object Pool Pattern

Hi 👋 In this article we’ll talk about the Object Pool pattern in Golang. The Object Pool pattern is a design pattern used in situations when constructing objects is a costly operation, for example building an HTTPClient or DatabaseClient object can take some time. By having a pool of resources, the resources are requested from the pool when needed and then returned when not needed so they can be reused later. ...

August 21, 2022 · 6 min · Denis Nuțiu

Improving the throughput of a Producer ✈

Hello 👋, In this article I will give you some tips on how to improve the throughput of a message producer. I had to write a Golang based application which would consume messages from Apache Kafka and send them into a sink using HTTP JSON / HTTP Protocol Buffers. To see if my idea works, I started using a naïve approach in which I polled Kafka for messages and then send each message into the sink, one at a time. This worked, but it was slow. ...

August 28, 2021 · 4 min · Denis Nuțiu