Posts

Showing posts with the label go

Managing Go Processes

Image
  Introduction: The Challenge of Managing Blocking Processes While working on an application that required executing a command to run a blocking program, such as a TCP/HTTP server, I encountered an interesting challenge. I needed a way to stop the application and its child processes when a signal was sent to the main program, such as SIGINT (Ctrl+C) or SIGTERM . This blog post shares my journey and the solutions I found to manage processes effectively in a Go application, focusing on Linux environments. Executing Commands with the "os/exec" package In my experience with the os/exec package in Go processe , I used exec.Command to run an external command, similar to how others use this package to execute external commands. However, when I tried to stop the command using cmd.Process.Kill() , I faced an issue. For eg: when running a command like watch date > date.txt , I noticed that the process continued to run in the background even after calling cmd.Process.Kill() . Yo...

Why I Switched to Table Driven Testing approach in Go

Image
  Table driven tests , also known as parameterized tests, have became very popular over the past few years, due to their ability to eliminate repetition. Table driven tests make it quite a bit easier to re-use the same values for different sets of tests by just moving the table outside of the scope of the test function. Different tests may benefit from the same input, and each test may have completely different configration, concurrency etc... The table structure Well, think of it as a systematic way of testing your code by providing a set of inputs and expected outputs in a structured table format. Instead of writing individual test cases for each input-output pair, we organize them neatly in a table, making it easier to manage and maintain our tests. Each row in the table represents a separate test case, and the columns represent different aspects or parameters of the test, such as inputs, expected outputs, and any other relevant conditions. Here's a simplified example of what a...