mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-30 09:43:17 -04:00 
			
		
		
		
	plugin/forward: remove lenc and lencOut channels (#1726)
Remove these 2 channels, as they were only used in testing and complicate things if we want to do a clean stop() Less is more.
This commit is contained in:
		| @@ -31,11 +31,6 @@ type transport struct { | |||||||
| 	dial  chan string | 	dial  chan string | ||||||
| 	yield chan connErr | 	yield chan connErr | ||||||
| 	ret   chan connErr | 	ret   chan connErr | ||||||
|  |  | ||||||
| 	// Aid in testing, gets length of cache in data-race safe manner. |  | ||||||
| 	lenc    chan bool |  | ||||||
| 	lencOut chan int |  | ||||||
|  |  | ||||||
| 	stop  chan bool | 	stop  chan bool | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -48,8 +43,6 @@ func newTransport(addr string, tlsConfig *tls.Config) *transport { | |||||||
| 		yield:  make(chan connErr), | 		yield:  make(chan connErr), | ||||||
| 		ret:    make(chan connErr), | 		ret:    make(chan connErr), | ||||||
| 		stop:   make(chan bool), | 		stop:   make(chan bool), | ||||||
| 		lenc:    make(chan bool), |  | ||||||
| 		lencOut: make(chan int), |  | ||||||
| 	} | 	} | ||||||
| 	go t.connManager() | 	go t.connManager() | ||||||
| 	return t | 	return t | ||||||
| @@ -65,13 +58,6 @@ func (t *transport) len() int { | |||||||
| 	return l | 	return l | ||||||
| } | } | ||||||
|  |  | ||||||
| // Len returns the number of connections in the cache. |  | ||||||
| func (t *transport) Len() int { |  | ||||||
| 	t.lenc <- true |  | ||||||
| 	l := <-t.lencOut |  | ||||||
| 	return l |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // connManagers manages the persistent connection cache for UDP and TCP. | // connManagers manages the persistent connection cache for UDP and TCP. | ||||||
| func (t *transport) connManager() { | func (t *transport) connManager() { | ||||||
|  |  | ||||||
| @@ -128,13 +114,6 @@ Wait: | |||||||
|  |  | ||||||
| 		case <-t.stop: | 		case <-t.stop: | ||||||
| 			return | 			return | ||||||
|  |  | ||||||
| 		case <-t.lenc: |  | ||||||
| 			l := 0 |  | ||||||
| 			for _, conns := range t.conns { |  | ||||||
| 				l += len(conns) |  | ||||||
| 			} |  | ||||||
| 			t.lencOut <- l |  | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -30,28 +30,4 @@ func TestPersistent(t *testing.T) { | |||||||
| 	tr.Yield(c1) | 	tr.Yield(c1) | ||||||
| 	tr.Yield(c2) | 	tr.Yield(c2) | ||||||
| 	tr.Yield(c3) | 	tr.Yield(c3) | ||||||
|  |  | ||||||
| 	if x := tr.Len(); x != 3 { |  | ||||||
| 		t.Errorf("Expected cache size to be 3, got %d", x) |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	c4, cache4, _ := tr.Dial("udp") |  | ||||||
| 	if x := tr.Len(); x != 2 { |  | ||||||
| 		t.Errorf("Expected cache size to be 2, got %d", x) |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	c5, cache5, _ := tr.Dial("udp") |  | ||||||
| 	if x := tr.Len(); x != 1 { |  | ||||||
| 		t.Errorf("Expected cache size to be 1, got %d", x) |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	if cache4 == false || cache5 == false { |  | ||||||
| 		t.Errorf("Expected cached connection") |  | ||||||
| 	} |  | ||||||
| 	tr.Yield(c4) |  | ||||||
| 	tr.Yield(c5) |  | ||||||
|  |  | ||||||
| 	if x := tr.Len(); x != 3 { |  | ||||||
| 		t.Errorf("Expected cache size to be 3, got %d", x) |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user