mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 02:03:20 -04:00 
			
		
		
		
	Add traffic plugin
This allows for advanced loadbalancing and maybe geoIP loadbalancing. Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
		
							
								
								
									
										38
									
								
								plugin/traffic/assignment_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								plugin/traffic/assignment_test.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | ||||
| package traffic | ||||
|  | ||||
| import ( | ||||
| 	"math/rand" | ||||
| 	"net" | ||||
| 	"testing" | ||||
| 	"time" | ||||
| ) | ||||
|  | ||||
| func TestAssignment(t *testing.T) { | ||||
| 	rand.Seed(int64(time.Now().Nanosecond())) | ||||
|  | ||||
| 	backends := []*backend{ | ||||
| 		{net.IPv4zero, 0, 6}, | ||||
| 		{net.IPv4allrouter, 0, 4}, | ||||
| 		{net.IPv4allsys, 0, 0}, | ||||
| 	} | ||||
| 	a := assignment{"www.example.org", backends} | ||||
|  | ||||
| 	// should never get 0 weight, could be improved to check the difference between 4 and 6. | ||||
| 	for i := 0; i < 100; i++ { | ||||
| 		if x := a.Select(); x.weight == 0 { | ||||
| 			t.Errorf("Expected non-nil weight for Select, got %v", x) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestAssignmentZero(t *testing.T) { | ||||
| 	rand.Seed(int64(time.Now().Nanosecond())) | ||||
|  | ||||
| 	backends := []*backend{ | ||||
| 		{net.IPv4zero, 0, 0}, | ||||
| 	} | ||||
| 	a := assignment{"www.example.org", backends} | ||||
| 	if x := a.Select(); x != nil { | ||||
| 		t.Errorf("Expected nil for Select, got %v", x) | ||||
| 	} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user