Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/go-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Coverage

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
fetch-depth: '0'

- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: 1.24
cache: 'true'

- name: Build
run: go install

- name: Test
run: |
go test -v -cover ./... -coverprofile coverage.out -coverpkg ./...
go tool cover -func coverage.out -o coverage.out # Replaces coverage.out with the analysis of coverage.out

- name: Go Coverage Badge
uses: tj-actions/coverage-badge-go@v3
with:
green: 80
filename: coverage.out

- uses: stefanzweifel/git-auto-commit-action@v6
id: auto-commit-action
with:
commit_message: Apply Code Coverage Badge
file_pattern: ./README.md
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Exitplan
[![Go Reference](https://pkg.go.dev/badge/github.com/struct0x/exitplan.svg)](https://pkg.go.dev/github.com/struct0x/exitplan)
![Coverage](https://img.shields.io/badge/Coverage-83.2%25-brightgreen)

A Go library for managing the lifecycle of an application with graceful shutdown capabilities.

[![Go Reference](https://pkg.go.dev/badge/github.com/struct0x/exitplan.svg)](https://pkg.go.dev/github.com/struct0x/exitplan)

## Overview

The Exitplan library provides a simple mechanism for managing the lifetime of an application.
Expand Down
7 changes: 4 additions & 3 deletions exitplan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"slices"
"sync"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -165,10 +166,10 @@ func TestOnExitTimeout(t *testing.T) {

l := exitplan.New()

called := false
called := atomic.Bool{}
l.OnExit(func() {
time.Sleep(2 * timeout)
called = true
called.Store(true)
}, exitplan.Timeout(timeout))

go func() {
Expand All @@ -186,7 +187,7 @@ func TestOnExitTimeout(t *testing.T) {
t.Errorf("expected timeout between %v and %v, got %v", timeout-timeoutJitter, timeout+timeoutJitter, end.Sub(start))
}

if called {
if called.Load() {
t.Error("callback was called")
}
}
Loading