<div class="Article" data-slug="/blog/testing-time">
<h1 class="small"><a href="/blog/">The Go Blog</a></h1>
<h1>Testing Time (and other asyncronicities)</h1>
<p class="author">
Damien Neil<br>
26 August 2025
</p>
<div class='markdown'>
In Go 1.24, we introduced the testing/synctest
package as an experimental package.
This package can significantly simplify writing tests for concurrent,
asynchronous code.
In Go 1.25, the testing/synctest
package has graduated from experiment
to general availability.
What follows is the blog version of my talk on
the testing/synctest
package
at GopherCon Europe 2025 in Berlin.
What is an asynchronous function?
A synchronous function is pretty simple.
You call it, it does something, and it returns.
An asynchronous function is different.
You call it, it returns, and then it does something.
As a concrete, if somewhat artificial, example,
the following Cleanup
function is synchronous.
You call it, it deletes a cache directory, and it returns.
func (c *Cache) Cleanup() {
os.RemoveAll(c.cacheDir)
}
CleanupInBackground
is an asynchronous function.
You call it, it returns, and the cache directory is deleted…sooner or later.
func (c *Cache) CleanupInBackground() {
go os.RemoveAll(c.cacheDir)
}
Sometimes an asynchronous function does something in the future.
For example, the context
package’s WithDeadline
function
returns a context which will be canceled in the future.
package context
// WithDeadline returns a derived context
// with a deadline no later than d.
func WithDeadline(pare…