github.com/flavio/docker@v0.1.3-0.20170117145210-f63d1a6eec47/pkg/plugins/plugin_test.go (about)

     1  package plugins
     2  
     3  import (
     4  	"path/filepath"
     5  	"runtime"
     6  	"sync"
     7  	"testing"
     8  	"time"
     9  )
    10  
    11  // regression test for deadlock in handlers
    12  func TestPluginAddHandler(t *testing.T) {
    13  	// make a plugin which is pre-activated
    14  	p := &Plugin{activateWait: sync.NewCond(&sync.Mutex{})}
    15  	p.Manifest = &Manifest{Implements: []string{"bananas"}}
    16  	storage.plugins["qwerty"] = p
    17  
    18  	testActive(t, p)
    19  	Handle("bananas", func(_ string, _ *Client) {})
    20  	testActive(t, p)
    21  }
    22  
    23  func testActive(t *testing.T, p *Plugin) {
    24  	done := make(chan struct{})
    25  	go func() {
    26  		p.waitActive()
    27  		close(done)
    28  	}()
    29  
    30  	select {
    31  	case <-time.After(100 * time.Millisecond):
    32  		_, f, l, _ := runtime.Caller(1)
    33  		t.Fatalf("%s:%d: deadlock in waitActive", filepath.Base(f), l)
    34  	case <-done:
    35  	}
    36  
    37  }