Skip to main content

Unboxing Packages: A Requiem for scheduled_test

Long long ago in the dawning days of Dart, when Futures were new and Streams unknown, Bob saw the need for a package manager to bring the people together. Together he and I spun formless bits into code and wove that code into pub, which even today carries code into the eager hands of Dartisans. In those olden days, we had no modern marvels such as the twins async and await, and our tests grew heavy and graceless under the weight of their chain()s1.

So it was that I came up with an idea for a new way of writing tests. Instead of gluing the steps together with the cumbersome Future API, each step would register an asynchronous callback in a queue. Once all the steps were queued up, the library would run them in order. All the API boilerplate would be hidden away from the user, and the tests would look nice and clean. After honing this technique on pub’s tests, I brought it out into its own package, which I called scheduled_test.

If this whole idea of queuing up tasks and running them later sounds complicated, that’s because it was. scheduled_test did a great job of pushing complexity away from test cases, but in return any infrastructure that ran those test cases got much more complex. You couldn’t just write normal Dart code, you had to make sure to wrap everything in schedule() and allow users to pass in Futures and all sorts of hassle. I had created a better sort of tests, but not one without flaws.

The Beginning of the End

Then in Dart 1.9, support for async and await landed and completely changed the equation. No longer did asynchronous APIs have to involve a mess of nesting and callbacks—even the most Future-heavy tests were free to look like plain old synchronous code with some extra keywords sprinkled on top. The driving purpose of scheduled_test, making asynchronous tests look simple and comprehensible, was now supported by the language itself.

You may then wonder, why didn’t scheduled_test fade into obscurity and disuse fifteen Dart versions ago? You may ask, “Natalie, when you created the new test package, why did you decide to use scheduled_test when it no longer had a purpose?” The answer to these questions is infrastructure.

Over the years we had built up a number of APIs around the core functionality of scheduled_test, and even when that functionality got less relevant the APIs that used it were very useful. We couldn’t migrate old code until we had a good replacement, and even for new code scheduled_test was still the best option for testing files and subprocesses.

The Final Blow

This year2, one of my goals was to finally rid the world of scheduled_test once and for all. This meant buckling down and replacing all the infrastructure we’d built on it over the years with new packages that use nothing more than dart:async and the base test API. It took a lot of work, but I did it. I’m pleased to say that pub no longer uses scheduled_test, nor does test. These were scheduled_test’s biggest users, and they serve as a proof-of-concept for the suitability of its replacements:

  • The scheduled_test/descriptor library, which provided a simple and readable API for creating and validating files and directories, is replaced by the test_descriptor package.

  • The scheduled_test/scheduled_process library, which wrapped dart:io’s Process library to provide better debugging and easier line-by-line access to the standard IO streams, is replaced by the test_process package.

  • The scheduled_test/scheduled_stream library provided a pull-based API for streams which has been replaced by the async package’s StreamQueue class, and the stream matchers have been replaced by a suite of matchers in test itself.

  • The scheduled_test/scheduled_server library, which provided a server that validates and handles individual requests, has been moved to the shelf_test_handler package.

  • The core of scheduled_test may be going away, but it had a few useful features that I salvaged. The test package can now print a message only when a test fails and add tear-downs at runtime, both of which were originally supported in scheduled_test only.

I hope these APIs can be used more widely now that they’re no longer tangled up with scheduled_test. In fact, I encourage you to try them out right away if they seem useful—or write your own libraries if they don’t!

  1. Fun fact: Future.then() used to be called Future.chain()!
  2. Excluding April and parts of March and May, when I was out recovering from surgery. I’m doing great, thanks for asking! 😊

Popular posts from this blog

Dart in 2016: The fastest growing programming language at Google, 2nd fastest growing in TIOBE Index

Dart was the fastest growing programming language at Google in 2016 with millions of lines of code written. It also made it to TIOBE Index Top 20 this month (see TIOBE's methodology).

It takes time to build something as ambitious as Dart and, in some ways, Dart is still in its infancy. But we're glad the hard work is starting to pay off.

Many thanks to our amazing community!

We're going to celebrate by ... releasing 1.22 next week (as per our usual 6 week release schedule).

The new Google AdSense user interface: built with AngularDart

AdSense is a free, simple way to earn money by placing ads on your website. The team just launched a completely new version of their app for publishers. Read all about it here. We asked Daniel White, the tech lead for the project, some questions because the new UI happens to be built with Dart and Angular2.

AdSense launched way back in 2003. How long is it since the last big redesign?
Last big redesign was called ‘AdSense 3’ and launched about 6 years ago. It was written in Google Web Toolkit (GWT) and the UI has evolved through several iterations - but this is the first ground-up redesign in 6 years. There are a number of long-standing UX issues that we’ve taken the opportunity to solve. A big shout-out to our UX team who’ve been 100% behind this project. We couldn’t have done it without them!

How many software engineers worked on the project?
Purely on the AdSense applications, we have a team of close to 100. Around 25% of them write Dart.

How many lines of code?
We have around 160K LO…

A stronger Dart for everyone

We are constantly asking ourselves:
How do we make developers even more productive when writing Dart apps? We believe that a critical part of the answer to this question is to make strongmode – a sound static type system for Dart – the standard for all Dart developers.

Teams that use Dart to build apps like Soundtrap, AdWords, AdSense, and Greentea say they really enjoy using strong mode features, such as early error detection. In fact, teams that have switched completely to strong mode cite not only early error detection but also better code readability and maintainability as major benefits. We hear this both from small teams and – even more so – from large teams with hundreds of developers writing and maintaining millions of lines of Dart code. As Björn Sperber from Soundtrap says,
Strong mode and the smooth integration with IntelliJ is a joy to use and a huge improvement. If you’ve tried out Flutter, you’ve already used strong mode checks from the Dart analyzer.

Given the benefits …