Skip to content

Commit

Permalink
new post
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickrbc committed Mar 16, 2024
1 parent 212fd3f commit cfc04e8
Show file tree
Hide file tree
Showing 19 changed files with 463 additions and 47 deletions.
1 change: 0 additions & 1 deletion _posts/2019-04-01-re-wireless-repeater.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ layout: post
title: "Reverse engineering a wireless repeater - Part I"
date: 2019-04-01 17:21:00 -0300
comments: true
categories:
---

Do you have an old router left behind in your room? Ever wondered how it really
Expand Down
1 change: 0 additions & 1 deletion _posts/2019-04-06-cryptopals-the-basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ layout: post
title: "Cryptopals: The basics"
date: 2019-04-06 16:42:00 -0300
comments: true
categories:
---

If you have **any** kind of interest in crypto you should probably check this
Expand Down
1 change: 0 additions & 1 deletion _posts/2019-06-01-re-wireless-repeater-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ layout: post
title: "Reverse engineering a wireless repeater - Part II"
date: 2019-06-01 21:25:00 -0300
comments: true
categories:
---


Expand Down
1 change: 0 additions & 1 deletion _posts/2021-07-31-wildcard-subdomain-enum.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ layout: post
title: 'Subdomain enumeration with wildcard records '
date: 2021-07-31 13:49:00 -0300
comments: true
categories: footprinting, subdomain, dns
---

**TL;DR**
Expand Down
1 change: 0 additions & 1 deletion _posts/2022-12-26-the-social-media-trap.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ layout: post
title: The social media trap
date: 2022-12-26 21:32:00 -0300
comments: true
categories:
---

There's no way one can avoid social media completely. We are social creatures.
Expand Down
68 changes: 68 additions & 0 deletions _posts/2024-03-16-jest-slow-tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
layout: post
title: Migrating away from Jest and achieving over 90% reduction in running time
date: 2024-03-16 13:42:00 -0300
comments: true
---

Unfortunately, I've been using Jest since 2019. No offense to the Jest team – I'm pretty sure they're awesome and way smarter than I am, but I wish I had made this move earlier in this project.

I'm not talking about UI testing here, so assume everything I'm saying is about server-side JS. If you're happy with Jest, don't switch! I'm not trying to convince anyone. I'm just sharing my experience because I bet there are people out there in the same situation as I was.

The decision to go with Jest wasn't well thought out. At the time, I wasn't heavily involved in software development, so I opted for the well-known, fully-fledged test framework. It seemed promising initially, with its great API.

However, after hundreds of tests, things started to break a lot. Memory leaks began to surface, the number of hacky flags multiplied, and visiting Jest's issues tab became routine.

## The problem

Jests loads [modules over and over again,](https://github.com/jestjs/jest/issues/10550) leading to a memory leak. It is [designed in a way](https://chanind.github.io/javascript/2019/10/12/jest-tests-memory-leak.html) that makes those problems arise [very likely](https://github.com/jestjs/jest/issues/6814), specially in backend projects that are getting big. I'm not going to try to describe the kind of issues here, but you can find them pretty easy [there](https://github.com/search?q=repo%3Ajestjs%2Fjest+memory&type=issues). I'm just going to leave some leads for the poor users that are still fighting this battle.

1. **jest —logHeapUsage**
\
As I've mentioned before, [memory](https://github.com/jaredjj3/jest-memory-leak-demo) [leaks](https://github.com/smolijar/jest-is-a-rude-needy-clown-and-eats-lot-of-memory?tab=readme-ov-file) [will](https://github.com/jestjs/jest/issues/12142) [be](https://github.com/jestjs/jest/issues/7311) [your](https://github.com/jestjs/jest/issues/7874) [best](https://github.com/jestjs/jest/pull/8331) [friend](https://github.com/jestjs/jest/issues/11956), so you'd better watch your heap usage to spot sudden growth.

2. **jest —maxWorkers=50%**
\
Some [benchmarks](https://ivantanev.com/make-jest-faster/) show that running with this configuration might make your tests run up to 20% faster. However, you have to test it in your project; some folks said it made things worse.

3. **jest —runInBand**
\
This command runs all tests serially in the current process instead of creating a worker pool of child processes. They say it's useful for debugging, but oddly enough, some people reported that it can actually improve performance.

4. **jest —changedSince**
\
If you run a workflow for each PR update, your tests will run a LOT. So, if you have limited compute minutes or a constrained CI pipeline, this flag can significantly reduce the time your PR workflows take.

5. **jest-slow-test-reporter**
\
You can use this reporter to view which tests are the slowest in your project and start tackling them first.

6. **Exposing Node.js gargabe collector**
\
In some cases, running Node with the flag **`--expose-gc`** seems to handle memory leaks better.

### Not good enough

Some of these strategies significantly reduced the running time during this period. However, the process of learning and implementing them came at the expense of delivery time, which is ultimately more critical.

The tests were so sluggish that I resorted to running them only on the module we were currently developing, then solely on the changed modules in the PR, and finally, all tests were run only when merging to the main branch. Unfortunately, this approach resulted in delays in identifying bugs.

The tests were so time-consuming that I found myself hesitating to write tests for certain features, worrying about the additional build process time they would cause. At this point, I realized it was time to make the switch.

## Switching to Mocha

I used Mocha a decade ago and it was awesome. So, I thought transitioning back to it would be smooth sailing. Over the past years, I've been seeing [people](https://github.com/jestjs/jest/issues/7832#issuecomment-1053545855) [throwing](https://github.com/jestjs/jest/issues/7963#issuecomment-802129978) [out](https://github.com/jestjs/jest/issues/7631#issuecomment-496335097) the idea of switching from Jest to Mocha, and always I found it [funny](https://github.com/jestjs/jest/issues/9980#issuecomment-1808310819). I remember there were a lot of guides and people talking about migrating from Mocha to Jest. Like me, most of people would assume the newer tool would have a better or at least similar performance.

The migration was much easier, than expected. A couple of replace cases and and less than an hour refactoring some code. The tricker part was the mock engine, which isn't included in Mocha.

I could have used [Sinon.js](https://sinonjs.org/) for that, but I really like the idea of one day not relying on any testing libraries. I even considered using only the new Node.js built-in test runner, but it's not quite there yet for me. So, I decided to stick with just the built-in [MockTracker](https://nodejs.org/api/test.html#class-mocktracker).

Trying things out was mind-blowing. Single tests that were taking 3 seconds with Jest would run in less than 200ms with Mocha. It shouldn't be a surprise – what I was running shouldn't take so long, but I had gotten used to that slowness. In the end, our test running time reduced from more than 12 minutes to less than 40 seconds.

The speed of Mocha helped us uncover hidden bugs that would occasionally fail tests because they only occurred under very specific conditions – conditions that were unlikely to be met in Jest due to its slower performance.

## Conclusion

I still use Jest on some smaller repositories that I maintain, and I'm not mad enough to migrate them until they become a problem. However, for future projects, I'll definitely opt for Mocha or the Node.js test runner.

The thing is, even if there's a way to optimize Jest and run thousands of tests in a reasonable time, there's something wrong when simply switching the testing framework results in significantly faster performance. Do you agree? Do you have any similar experiences? I'd love to hear about them.
9 changes: 5 additions & 4 deletions _site/2019/04/01/re-wireless-repeater.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<meta name="twitter:card" content="summary" />
<meta property="twitter:title" content="Reverse engineering a wireless repeater - Part I" />
<script type="application/ld+json">
{"headline":"Reverse engineering a wireless repeater - Part I","url":"http://localhost:4000/2019/04/01/re-wireless-repeater","dateModified":"2019-04-01T17:21:00-03:00","datePublished":"2019-04-01T17:21:00-03:00","mainEntityOfPage":{"@type":"WebPage","@id":"http://localhost:4000/2019/04/01/re-wireless-repeater"},"description":"Do you have an old router left behind in your room? Ever wondered how it really works inside? Sit tight and get ready, because this is going to be a series of blog posts about reverse engineering a wireless repeater. The methodology here can be applied to other IoT devices.","@type":"BlogPosting","@context":"https://schema.org"}</script>
{"url":"http://localhost:4000/2019/04/01/re-wireless-repeater","headline":"Reverse engineering a wireless repeater - Part I","dateModified":"2019-04-01T17:21:00-03:00","datePublished":"2019-04-01T17:21:00-03:00","mainEntityOfPage":{"@type":"WebPage","@id":"http://localhost:4000/2019/04/01/re-wireless-repeater"},"description":"Do you have an old router left behind in your room? Ever wondered how it really works inside? Sit tight and get ready, because this is going to be a series of blog posts about reverse engineering a wireless repeater. The methodology here can be applied to other IoT devices.","@type":"BlogPosting","@context":"https://schema.org"}</script>
<!-- End Jekyll SEO tag -->
<link rel="stylesheet" href="/assets/main.css"><link type="application/atom+xml" rel="alternate" href="http://localhost:4000/feed.xml" title="patrickrbc" /></head>
<body><header class="site-header">
Expand Down Expand Up @@ -247,14 +247,15 @@ <h1 id="references">References</h1>
</div>

</footer>
<script async
src="https://www.googletagmanager.com/gtag/js?id=UA-137241651-1"></script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-Q4C55092PY"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-137241651-1');

gtag('config', 'G-Q4C55092PY');
</script>

<script>
window.onload = function () {
setTheme(localStorage.getItem('theme'))
Expand Down
9 changes: 5 additions & 4 deletions _site/2019/04/06/cryptopals-the-basics.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<meta name="twitter:card" content="summary" />
<meta property="twitter:title" content="Cryptopals: The basics" />
<script type="application/ld+json">
{"headline":"Cryptopals: The basics","url":"http://localhost:4000/2019/04/06/cryptopals-the-basics","dateModified":"2019-04-06T16:42:00-03:00","datePublished":"2019-04-06T16:42:00-03:00","mainEntityOfPage":{"@type":"WebPage","@id":"http://localhost:4000/2019/04/06/cryptopals-the-basics"},"description":"If you have any kind of interest in crypto you should probably check this out. Recently, I started doing the Cryptopals, which are a series of cryptography challenges created by the formerly Matasano Security team. They are a collection of 48 exercises divided in 8 sets. I have just finished the first set but I can guarantee you that it was already a lot of fun and learning.","@type":"BlogPosting","@context":"https://schema.org"}</script>
{"url":"http://localhost:4000/2019/04/06/cryptopals-the-basics","headline":"Cryptopals: The basics","dateModified":"2019-04-06T16:42:00-03:00","datePublished":"2019-04-06T16:42:00-03:00","mainEntityOfPage":{"@type":"WebPage","@id":"http://localhost:4000/2019/04/06/cryptopals-the-basics"},"description":"If you have any kind of interest in crypto you should probably check this out. Recently, I started doing the Cryptopals, which are a series of cryptography challenges created by the formerly Matasano Security team. They are a collection of 48 exercises divided in 8 sets. I have just finished the first set but I can guarantee you that it was already a lot of fun and learning.","@type":"BlogPosting","@context":"https://schema.org"}</script>
<!-- End Jekyll SEO tag -->
<link rel="stylesheet" href="/assets/main.css"><link type="application/atom+xml" rel="alternate" href="http://localhost:4000/feed.xml" title="patrickrbc" /></head>
<body><header class="site-header">
Expand Down Expand Up @@ -534,14 +534,15 @@ <h1 id="references">References</h1>
</div>

</footer>
<script async
src="https://www.googletagmanager.com/gtag/js?id=UA-137241651-1"></script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-Q4C55092PY"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-137241651-1');

gtag('config', 'G-Q4C55092PY');
</script>

<script>
window.onload = function () {
setTheme(localStorage.getItem('theme'))
Expand Down
9 changes: 5 additions & 4 deletions _site/2019/06/01/re-wireless-repeater-2.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<meta name="twitter:card" content="summary" />
<meta property="twitter:title" content="Reverse engineering a wireless repeater - Part II" />
<script type="application/ld+json">
{"headline":"Reverse engineering a wireless repeater - Part II","url":"http://localhost:4000/2019/06/01/re-wireless-repeater-2","dateModified":"2019-06-01T21:25:00-03:00","datePublished":"2019-06-01T21:25:00-03:00","mainEntityOfPage":{"@type":"WebPage","@id":"http://localhost:4000/2019/06/01/re-wireless-repeater-2"},"description":"This is the second part of a series of posts about reverse engineering a wireless repeater. Before reading this you might want to take a look at the first part, where I introduced the subject and explained how to gather some information without digging into the hardware. If you still haven’t downloaded the firmware of our target device you can get it here.","@type":"BlogPosting","@context":"https://schema.org"}</script>
{"url":"http://localhost:4000/2019/06/01/re-wireless-repeater-2","headline":"Reverse engineering a wireless repeater - Part II","dateModified":"2019-06-01T21:25:00-03:00","datePublished":"2019-06-01T21:25:00-03:00","mainEntityOfPage":{"@type":"WebPage","@id":"http://localhost:4000/2019/06/01/re-wireless-repeater-2"},"description":"This is the second part of a series of posts about reverse engineering a wireless repeater. Before reading this you might want to take a look at the first part, where I introduced the subject and explained how to gather some information without digging into the hardware. If you still haven’t downloaded the firmware of our target device you can get it here.","@type":"BlogPosting","@context":"https://schema.org"}</script>
<!-- End Jekyll SEO tag -->
<link rel="stylesheet" href="/assets/main.css"><link type="application/atom+xml" rel="alternate" href="http://localhost:4000/feed.xml" title="patrickrbc" /></head>
<body><header class="site-header">
Expand Down Expand Up @@ -506,14 +506,15 @@ <h1 id="references">References</h1>
</div>

</footer>
<script async
src="https://www.googletagmanager.com/gtag/js?id=UA-137241651-1"></script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-Q4C55092PY"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-137241651-1');

gtag('config', 'G-Q4C55092PY');
</script>

<script>
window.onload = function () {
setTheme(localStorage.getItem('theme'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
<meta property="og:locale" content="en_US" />
<meta name="description" content="TL;DR" />
<meta property="og:description" content="TL;DR" />
<link rel="canonical" href="http://localhost:4000/footprinting,/subdomain,/dns/2021/07/31/wildcard-subdomain-enum" />
<meta property="og:url" content="http://localhost:4000/footprinting,/subdomain,/dns/2021/07/31/wildcard-subdomain-enum" />
<link rel="canonical" href="http://localhost:4000/2021/07/31/wildcard-subdomain-enum" />
<meta property="og:url" content="http://localhost:4000/2021/07/31/wildcard-subdomain-enum" />
<meta property="og:site_name" content="patrickrbc" />
<meta property="og:type" content="article" />
<meta property="article:published_time" content="2021-07-31T13:49:00-03:00" />
<meta name="twitter:card" content="summary" />
<meta property="twitter:title" content="Subdomain enumeration with wildcard records" />
<script type="application/ld+json">
{"headline":"Subdomain enumeration with wildcard records","url":"http://localhost:4000/footprinting,/subdomain,/dns/2021/07/31/wildcard-subdomain-enum","dateModified":"2021-07-31T13:49:00-03:00","datePublished":"2021-07-31T13:49:00-03:00","mainEntityOfPage":{"@type":"WebPage","@id":"http://localhost:4000/footprinting,/subdomain,/dns/2021/07/31/wildcard-subdomain-enum"},"description":"TL;DR","@type":"BlogPosting","@context":"https://schema.org"}</script>
{"url":"http://localhost:4000/2021/07/31/wildcard-subdomain-enum","headline":"Subdomain enumeration with wildcard records","dateModified":"2021-07-31T13:49:00-03:00","datePublished":"2021-07-31T13:49:00-03:00","mainEntityOfPage":{"@type":"WebPage","@id":"http://localhost:4000/2021/07/31/wildcard-subdomain-enum"},"description":"TL;DR","@type":"BlogPosting","@context":"https://schema.org"}</script>
<!-- End Jekyll SEO tag -->
<link rel="stylesheet" href="/assets/main.css"><link type="application/atom+xml" rel="alternate" href="http://localhost:4000/feed.xml" title="patrickrbc" /></head>
<body><header class="site-header">
Expand Down Expand Up @@ -110,7 +110,7 @@ <h1 id="finding-interesting-stuff">Finding interesting stuff</h1>
<p>Do you have any tips for finding apps on records with wildcard?</p>

</div>
<a class="u-url" href="/footprinting,/subdomain,/dns/2021/07/31/wildcard-subdomain-enum" hidden></a>
<a class="u-url" href="/2021/07/31/wildcard-subdomain-enum" hidden></a>
</article>

</div>
Expand Down Expand Up @@ -197,14 +197,15 @@ <h1 id="finding-interesting-stuff">Finding interesting stuff</h1>
</div>

</footer>
<script async
src="https://www.googletagmanager.com/gtag/js?id=UA-137241651-1"></script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-Q4C55092PY"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-137241651-1');

gtag('config', 'G-Q4C55092PY');
</script>

<script>
window.onload = function () {
setTheme(localStorage.getItem('theme'))
Expand Down
9 changes: 5 additions & 4 deletions _site/2022/12/26/the-social-media-trap.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<meta name="twitter:card" content="summary" />
<meta property="twitter:title" content="The social media trap" />
<script type="application/ld+json">
{"headline":"The social media trap","url":"http://localhost:4000/2022/12/26/the-social-media-trap","dateModified":"2022-12-26T21:32:00-03:00","datePublished":"2022-12-26T21:32:00-03:00","mainEntityOfPage":{"@type":"WebPage","@id":"http://localhost:4000/2022/12/26/the-social-media-trap"},"description":"There’s no way one can avoid social media completely. We are social creatures. Even if you close all your accounts and remove all the apps, you would still be influenced by other people’s behaviors and opinions, and those probably got a high load of influence from social media and so on.","@type":"BlogPosting","@context":"https://schema.org"}</script>
{"url":"http://localhost:4000/2022/12/26/the-social-media-trap","headline":"The social media trap","dateModified":"2022-12-26T21:32:00-03:00","datePublished":"2022-12-26T21:32:00-03:00","mainEntityOfPage":{"@type":"WebPage","@id":"http://localhost:4000/2022/12/26/the-social-media-trap"},"description":"There’s no way one can avoid social media completely. We are social creatures. Even if you close all your accounts and remove all the apps, you would still be influenced by other people’s behaviors and opinions, and those probably got a high load of influence from social media and so on.","@type":"BlogPosting","@context":"https://schema.org"}</script>
<!-- End Jekyll SEO tag -->
<link rel="stylesheet" href="/assets/main.css"><link type="application/atom+xml" rel="alternate" href="http://localhost:4000/feed.xml" title="patrickrbc" /></head>
<body><header class="site-header">
Expand Down Expand Up @@ -160,14 +160,15 @@ <h1 class="post-title p-name" itemprop="name headline">The social media trap</h1
</div>

</footer>
<script async
src="https://www.googletagmanager.com/gtag/js?id=UA-137241651-1"></script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-Q4C55092PY"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-137241651-1');

gtag('config', 'G-Q4C55092PY');
</script>

<script>
window.onload = function () {
setTheme(localStorage.getItem('theme'))
Expand Down
Loading

0 comments on commit cfc04e8

Please sign in to comment.