File tree Expand file tree Collapse file tree
core/src/test/java/io/grpc/internal Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -140,6 +140,30 @@ public boolean isLoggable(LogRecord record) {
140140 }
141141 }
142142
143+ @ Test
144+ public void orphanedChannel_triggerWarningAndCoverage () {
145+ ManagedChannel mc = new TestManagedChannel ();
146+ final ReferenceQueue <ManagedChannelOrphanWrapper > refqueue = new ReferenceQueue <>();
147+ ConcurrentMap <ManagedChannelReference , ManagedChannelReference > refs =
148+ new ConcurrentHashMap <>();
149+
150+ // Create the wrapper but NEVER call shutdown
151+ ManagedChannelOrphanWrapper wrapper = new ManagedChannelOrphanWrapper (mc , refqueue , refs );
152+ wrapper = null ; // Make it eligible for GC
153+
154+ // Trigger GC and clean the queue to hit the !wasShutdown branch
155+ final AtomicInteger numOrphans = new AtomicInteger ();
156+ GcFinalization .awaitDone (new FinalizationPredicate () {
157+ @ Override
158+ public boolean isDone () {
159+ numOrphans .getAndAdd (ManagedChannelReference .cleanQueue (refqueue ));
160+ return numOrphans .get () > 0 ;
161+ }
162+ });
163+
164+ assertEquals (1 , numOrphans .get ());
165+ }
166+
143167 @ Test
144168 public void refCycleIsGCed () {
145169 ReferenceQueue <ManagedChannelOrphanWrapper > refqueue =
You can’t perform that action at this time.
0 commit comments