github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/lang/pipes/namedpipes_test.go (about)

     1  package pipes_test
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	_ "github.com/lmorg/murex/builtins/pipes/streams"
     8  	"github.com/lmorg/murex/lang/pipes"
     9  	"github.com/lmorg/murex/test/count"
    10  )
    11  
    12  func TestPipes(t *testing.T) {
    13  	count.Tests(t, 6)
    14  	pipes := pipes.NewNamed()
    15  
    16  	if len(pipes.Dump()) != 1 {
    17  		t.Errorf("Empty pipes != 1: %d", len(pipes.Dump()))
    18  	}
    19  
    20  	err := pipes.CreatePipe("test", "std", "")
    21  	if err != nil {
    22  		t.Error(err)
    23  	}
    24  
    25  	if len(pipes.Dump()) != 2 {
    26  		t.Errorf("Empty pipes != 2: %d", len(pipes.Dump()))
    27  	}
    28  
    29  	err = pipes.Close("test")
    30  	if err != nil {
    31  		t.Error(err)
    32  	}
    33  
    34  	if len(pipes.Dump()) != 2 {
    35  		t.Errorf("(pipe timeout exceeded too early) Empty pipes != 2: %d", len(pipes.Dump()))
    36  	}
    37  
    38  	time.Sleep(4 * time.Second)
    39  
    40  	if len(pipes.Dump()) != 1 {
    41  		t.Errorf("Empty pipes != 1: %d", len(pipes.Dump()))
    42  	}
    43  }