Просмотр исходного кода

allow ratelimiting progress reporting for testcases

Progress reports once in a while which is a bit to unpredictable for
testcases, so we enforce a steady progress for them in the hope that
this makes the tests (mostly test-apt-progress-fd) a bit more stable.

Git-Dch: Ignore
David Kalnischkies лет назад: 11
Родитель
Сommit
533fe3d139
3 измененных файлов с 23 добавлено и 16 удалено
  1. 9 5
      apt-pkg/acquire.cc
  2. 13 10
      test/integration/framework
  3. 1 1
      test/integration/test-acquire-same-repository-multiple-times

+ 9 - 5
apt-pkg/acquire.cc

@@ -955,7 +955,7 @@ std::string pkgAcquire::Queue::QItem::Custom600Headers() const		/*{{{*/
 // AcquireStatus::pkgAcquireStatus - Constructor			/*{{{*/
 // AcquireStatus::pkgAcquireStatus - Constructor			/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* */
 /* */
-pkgAcquireStatus::pkgAcquireStatus() : d(NULL), Percent(0), Update(true), MorePulses(false)
+pkgAcquireStatus::pkgAcquireStatus() : d(NULL), Percent(-1), Update(true), MorePulses(false)
 {
 {
    Start();
    Start();
 }
 }
@@ -1054,13 +1054,17 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
       Time = NewTime;
       Time = NewTime;
    }
    }
 
 
+   double const OldPercent = Percent;
    // calculate the percentage, if we have too little data assume 1%
    // calculate the percentage, if we have too little data assume 1%
    if (TotalBytes > 0 && UnfetchedReleaseFiles)
    if (TotalBytes > 0 && UnfetchedReleaseFiles)
       Percent = 0;
       Percent = 0;
-   else 
+   else
       // use both files and bytes because bytes can be unreliable
       // use both files and bytes because bytes can be unreliable
-      Percent = (0.8 * (CurrentBytes/float(TotalBytes)*100.0) + 
+      Percent = (0.8 * (CurrentBytes/float(TotalBytes)*100.0) +
                  0.2 * (CurrentItems/float(TotalItems)*100.0));
                  0.2 * (CurrentItems/float(TotalItems)*100.0));
+   double const DiffPercent = Percent - OldPercent;
+   if (DiffPercent < 0.001 && _config->FindB("Acquire::Progress::Diffpercent", false) == true)
+      return true;
 
 
    int fd = _config->FindI("APT::Status-Fd",-1);
    int fd = _config->FindI("APT::Status-Fd",-1);
    if(fd > 0) 
    if(fd > 0) 
@@ -1078,11 +1082,11 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
 	 snprintf(msg,sizeof(msg), _("Retrieving file %li of %li (%s remaining)"), i, TotalItems, TimeToStr(ETA).c_str());
 	 snprintf(msg,sizeof(msg), _("Retrieving file %li of %li (%s remaining)"), i, TotalItems, TimeToStr(ETA).c_str());
       else
       else
 	 snprintf(msg,sizeof(msg), _("Retrieving file %li of %li"), i, TotalItems);
 	 snprintf(msg,sizeof(msg), _("Retrieving file %li of %li"), i, TotalItems);
-	 
+
       // build the status str
       // build the status str
       status << "dlstatus:" << i
       status << "dlstatus:" << i
              << ":"  << std::setprecision(3) << Percent
              << ":"  << std::setprecision(3) << Percent
-             << ":" << msg 
+             << ":" << msg
              << endl;
              << endl;
 
 
       std::string const dlstatus = status.str();
       std::string const dlstatus = status.str();

+ 13 - 10
test/integration/framework

@@ -273,16 +273,19 @@ EOF
 	chmod +x "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg"
 	chmod +x "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg"
 	echo "Dir::Bin::dpkg \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg\";" > rootdir/etc/apt/apt.conf.d/99dpkg
 	echo "Dir::Bin::dpkg \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg\";" > rootdir/etc/apt/apt.conf.d/99dpkg
 
 
-	if ! command dpkg --assert-multi-arch >/dev/null 2>&1; then
-		echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf # Added to test multiarch before dpkg is ready for it…
-	fi
-	echo 'quiet::NoUpdate "true";' >> aptconfig.conf
-	echo 'quiet::NoStatistic "true";' >> aptconfig.conf
-	# too distracting for users, but helpful to detect changes
-	echo 'Acquire::Progress::Ignore::ShowErrorText "true";' >> aptconfig.conf
-	# in testcases, it can appear as if localhost has a rotation setup,
-	# hide this as we can't really deal with it properly
-	echo 'Acquire::Failure::ShowIP "false";' >> aptconfig.conf
+	{
+		if ! command dpkg --assert-multi-arch >/dev/null 2>&1; then
+			echo "DPKG::options:: \"--force-architecture\";" # Added to test multiarch before dpkg is ready for it…
+		fi
+		echo 'quiet::NoUpdate "true";'
+		echo 'quiet::NoStatistic "true";'
+		# too distracting for users, but helpful to detect changes
+		echo 'Acquire::Progress::Ignore::ShowErrorText "true";'
+		echo 'Acquire::Progress::Diffpercent "true";'
+		# in testcases, it can appear as if localhost has a rotation setup,
+		# hide this as we can't really deal with it properly
+		echo 'Acquire::Failure::ShowIP "false";'
+	} >> aptconfig.conf
 
 
 	cp "${TESTDIRECTORY}/apt.pem" "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
 	cp "${TESTDIRECTORY}/apt.pem" "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem"
 	if [ "$(id -u)" = '0' ]; then
 	if [ "$(id -u)" = '0' ]; then

+ 1 - 1
test/integration/test-acquire-same-repository-multiple-times

@@ -32,7 +32,7 @@ cat >$NEWMETHODS/file <<EOF
 while read line; do
 while read line; do
 	echo "\$line"
 	echo "\$line"
 	if [ -z "\$line" ]; then
 	if [ -z "\$line" ]; then
-		sleep 0.2
+		sleep 0.5
 	fi
 	fi
 done | $OLDMETHODS/file
 done | $OLDMETHODS/file
 EOF
 EOF