Skip to content

Commit

Permalink
Cache internal MMR build until all test suites have been run (#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
turt2live authored Nov 26, 2023
1 parent a32d068 commit a361f1e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/test_internals/deps_mmr.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"path"
"strconv"
"strings"
"sync/atomic"
"text/template"

"github.com/docker/docker/api/types"
Expand Down Expand Up @@ -41,6 +42,12 @@ type mmrContainer struct {

var mmrCachedImage string
var mmrCachedContext *os.File
var mmrCachedSuites atomic.Int32

func MarkUsingCachedMmrBuild() {
mmrCachedSuites.Add(1)
log.Println("+1 cached build usage")
}

func reuseMmrBuild(ctx context.Context) (string, error) {
if mmrCachedImage != "" {
Expand Down Expand Up @@ -188,6 +195,12 @@ func (c *mmrContainer) Logs() (io.ReadCloser, error) {
}

func TeardownMmrCaches() {
mmrCachedSuites.Add(-1)
if mmrCachedSuites.Load() > 0 {
log.Println("Not cleaning up MMR cached images: image still in use")
return
}

if mmrCachedContext != nil {
_ = mmrCachedContext.Close() // ignore errors because testcontainers might have already closed it
if err := os.Remove(mmrCachedContext.Name()); err != nil && !os.IsNotExist(err) {
Expand Down
4 changes: 4 additions & 0 deletions test/upload_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import (
"github.com/turt2live/matrix-media-repo/util"
)

func init() {
test_internals.MarkUsingCachedMmrBuild()
}

type UploadTestSuite struct {
suite.Suite
deps *test_internals.ContainerDeps
Expand Down

0 comments on commit a361f1e

Please sign in to comment.