github.com/sixexorg/magnetic-ring@v0.0.0-20191119090307-31705a21e419/central/mongokey/mongokey_test.go (about)

     1  package mongokey
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"os/signal"
     7  	"syscall"
     8  	"testing"
     9  	"time"
    10  )
    11  
    12  func TestChan(t *testing.T)  {
    13  	ch := make(chan string,1)
    14  
    15  	fmt.Printf("begin......\n")
    16  	go func() {
    17  		ticker := time.NewTicker(time.Second*5)
    18  
    19  		for  {
    20  			select {
    21  			case <- ticker.C:
    22  				ch <- time.Now().Format("15:04:05")
    23  			}
    24  		}
    25  
    26  	}()
    27  
    28  	for c := range ch {
    29  		fmt.Printf("c=%s\n",c)
    30  	}
    31  
    32  
    33  
    34  	c := make(chan os.Signal, 1)
    35  	signal.Notify(c, os.Interrupt, os.Kill, syscall.SIGTERM, syscall.SIGINT, syscall.SIGHUP)
    36  	<-c
    37  
    38  }
    39  
    40