VOL-2880: Reduction of Unit Test Time

Unit Test time before these changes was around 90 seconds.
With these minor changes we could reduce it to around 40 seconds.

Change-Id: I3abe7dc487117e31275862a2d0172e2bc85c2969
diff --git a/internal/pkg/core/device_handler.go b/internal/pkg/core/device_handler.go
index 74e1f30..6b7ca7e 100644
--- a/internal/pkg/core/device_handler.go
+++ b/internal/pkg/core/device_handler.go
@@ -532,6 +532,9 @@
 
 // doStateUp handle the olt up indication and update to voltha core
 func (dh *DeviceHandler) doStateUp(ctx context.Context) error {
+	//starting the stat collector
+	go startCollector(dh)
+
 	// Synchronous call to update device state - this method is run in its own go routine
 	if err := dh.coreProxy.DeviceStateUpdate(ctx, dh.device.Id, voltha.ConnectStatus_REACHABLE,
 		voltha.OperStatus_ACTIVE); err != nil {
@@ -744,8 +747,6 @@
 }
 
 func startCollector(dh *DeviceHandler) {
-	// Initial delay for OLT initialization
-	time.Sleep(1 * time.Minute)
 	logger.Debugf("Starting-Collector")
 	context := make(map[string]string)
 	for {
@@ -769,7 +770,6 @@
 				if val, ok := dh.activePorts.Load(i); ok && val == true {
 					cmpon := dh.portStats.collectPONMetrics(i)
 					logger.Debugf("Collect-PON-Metrics %v", cmpon)
-
 					go dh.portStats.publishMetrics("PONStats", cmpon, i, context, dh.deviceID)
 					logger.Debugf("Publish-PON-Metrics")
 				}
@@ -789,7 +789,6 @@
 		olterrors.NewErrAdapter("error-updating-performance-metrics", log.Fields{"device-id": device.Id}, err).LogAt(log.ErrorLevel)
 	}
 
-	go startCollector(dh)
 	go startHeartbeatCheck(ctx, dh)
 }
 
@@ -1400,6 +1399,9 @@
 	dh.discOnus = sync.Map{}
 	dh.onus = sync.Map{}
 
+	//stopping the stats collector
+	dh.stopCollector <- true
+
 	go dh.notifyChildDevices("unreachable")
 	cloned := proto.Clone(device).(*voltha.Device)
 	// Update the all pon ports state on that device to disable and NNI remains active as NNI remains active in openolt agent.
diff --git a/internal/pkg/core/device_handler_test.go b/internal/pkg/core/device_handler_test.go
index 4db1b93..9fd8127 100644
--- a/internal/pkg/core/device_handler_test.go
+++ b/internal/pkg/core/device_handler_test.go
@@ -965,6 +965,7 @@
 			if err := tt.devicehandler.doStateUp(ctx); (err != nil) != tt.wantErr {
 				t.Logf("DeviceHandler.doStateUp() error = %v, wantErr %v", err, tt.wantErr)
 			}
+			tt.devicehandler.stopCollector <- true //stop the stat collector invoked from doStateUp
 		})
 	}
 }
@@ -1177,7 +1178,7 @@
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 			go func() {
-				time.Sleep(66 * time.Second) // startCollector inside waits for 1 min, so we stop it after 6 secs of running
+				time.Sleep(5 * time.Second) // simulated wait time to stop startCollector
 				tt.args.dh.stopCollector <- true
 			}()
 			startCollector(tt.args.dh)