mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-10-31 02:27:19 -04:00 
			
		
		
		
	Fix race in test
Signed-off-by: Alexander Morozov <lk4d4@docker.com>
This commit is contained in:
		
							parent
							
								
									dc4a5ae1fd
								
							
						
					
					
						commit
						37eedf5cdc
					
				| @ -3,6 +3,7 @@ package markdown | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"strings" | ||||
| 	"sync" | ||||
| 	"testing" | ||||
| 	"time" | ||||
| ) | ||||
| @ -23,12 +24,18 @@ func TestWatcher(t *testing.T) { | ||||
| 	} | ||||
| 	out = "" | ||||
| 	i = 0 | ||||
| 	var mu sync.Mutex | ||||
| 	stopChan = TickerFunc(interval, func() { | ||||
| 		i++ | ||||
| 		mu.Lock() | ||||
| 		out += fmt.Sprint(i) | ||||
| 		mu.Unlock() | ||||
| 	}) | ||||
| 	time.Sleep(interval * 10) | ||||
| 	if !strings.HasPrefix(out, expected) || out == expected { | ||||
| 	mu.Lock() | ||||
| 	res := out | ||||
| 	mu.Unlock() | ||||
| 	if !strings.HasPrefix(res, expected) || res == expected { | ||||
| 		t.Fatalf("expected (%v) must be a proper prefix of out(%v).", expected, out) | ||||
| 	} | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user