Posts

Showing posts from April, 2024

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...

How I Simulated A Response From A Third Party App

Image
  Whether you're building a web application, a mobile app, or any other software product, integrating with third-party APIs is almost inevitable. But what happens when you need to test your application's behavior without relying on these external services? That's where the magic of simulation comes in handy. In this blog, we'll explore how you can simulate responses effectively, even if the actual service isn't available. What's the needed to simulate third party app? So, imagine you're developing an app that relies on various external services, like payment gateways or weather APIs. During development, waiting for these services to respond can slow you down significantly. Plus, what if the service is undergoing maintenance or has usage limitations? Simulating responses allows you to keep working without being dependent on these external factors. One approach is by using stubs. Stubs are like placeholders that mimic the behavior of the actual service. They ...

Getting code coverage data for each request coming to a python web server

Image
  In this blog, we will demonstrate how to get the coverage data for each incoming request on a python web server built using any web framework. What is Code Coverage ? Code coverage is a metric used in software testing to measure the extent to which the source code of a program has been executed during testing. It indicates the percentage of code that has been covered by the test cases. Code coverage analysis helps developers understand how thoroughly their tests exercise the codebase. Code coverage tools are used to collect data on code execution during testing and generate reports showing the coverage metrics. These reports help developers identify areas of the code that are not adequately covered by tests, allowing them to write additional tests to improve coverage and increase confidence in the software's correctness and reliability. What does it mean to get coverage data for each request ? Obtaining coverage data for each request coming to a web server offers several benefit...

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...