Microsoft Team Foundation Server Express 2012 - How to clear in tbl_TestResult (old test results)

I have installed Microsoft Team Foundation Server Express 2012.

The tbl_TestResult table is using 7000 MB of my db space.

I tried to find information on how to clear this table but couldn't find a way to do it.

When I want to check out new files in TFS, I get error TF30042: Database is full ...

In Visul Studio, I removed all visible tests, but the size of tbl_TestResult just decreased very little.

Can anyone explain to me how can I clear all test results correctly?

+3


source to share


4 answers


I am using the TFS API to remove old test runs. Here's some sample code:

TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri("http://tfs2012:8080/tfs/DefaultCollection/"));

TestManagementService testManagementService = tpc.GetService<TestManagementService>();

ITestManagementTeamProject teamProject = testManagementService.GetTeamProject("MyProject");

int totalRuns = teamProject.TestRuns.Count("SELECT * FROM TestRun");

// Limit by date, so the query doesn't take too long.
string query = "SELECT * FROM TestRun WHERE CreationDate < '2013/07/01'";
int numTotalToDelete = teamProject.TestRuns.Count(query);

if (numTotalToDelete == 0) { return; }

// Only delete 500 at a time, to give SQL Server time to breathe (don't ask).
var runsToDelete = teamProject.TestRuns.Query(query, false)
                              .Take(500);
teamProject.TestRuns.Delete(runsToDelete);

      



The query syntax comes from here: http://blogs.msdn.com/b/duat_le/archive/2010/02/25/wiql-for-test.aspx

+2


source


We had the same problem for ours at prem TFS. This is how we did it for TFS 2015 to TFS 2017.

  • Install Microsoft Visual Studio Team Foundation Server 2015 Power Tools to access the Test Additions Cleaner (TAC), tcmpt.exe .
  • He sets c:\Program Files (x86)\Microsoft Team Foundation Server 2015 Power Tools

  • Examples of TAC settings are located in the installation folder, <INSTALL_DIR>\TestAttachmentCleaner_samples_settingsfile

  • Create your own settings file, for example all-100mb.xml

    file:
<DeletionCriteria>
<TestRun>
    <Created Before="2016-01-01" />
</TestRun>
<Attachment>
    <Extensions>
    <Include value="wmv" />
    <Include value="xesc" />
    <Include value="trmx" />
    </Extensions>
    <!-- size in MB -->
    <SizeInMB GreaterThan="100" />
</Attachment>
<LinkedBugs>
    <Exclude state="Active" />
</LinkedBugs>
</DeletionCriteria>

      



  1. The above config file removes test attachments of inactive test runs larger than 100MB with extensions: wmv, xesc, trmx.
  2. Try a test try to see the result with this command: tcmpt.exe AttachmentCleanup /settingsfile:"all-100mb.xml" /mode:preview /collection:"https://tfs.contoso.com/DefaultCollection" /teamproject:"TeamProjectName" /outputfile:all-100mb.log"

  3. This creates a very verbose log file that contains the key information you need, for example: ------------ Summary ------------ Number of attachments affected: 339 Total size of attachments: 39646,7 MB Elapsed time was 247,94 seconds

  4. When you are satisfied with the result, do the following:
    • Disable transaction logs for your TFS database if you are using an MSSQL server.
    • If you don't, you can grow your transaction logs faster than removing test attachments.
  5. Run tcmpt.exe

    above command without parameter /mode:preview

    to remove test attachments.
  6. When done, run these 2 stored procedures from the TFS database: EXEC dbo.prc_DeleteUnusedContent 1 EXEC dbo.prc_DeleteUnusedFiles 1, 0, 1000

    • Stored procedures remove empty rows from the database.
    • If the stored procedures last for less than 1 second, wait for a while and rerun them.
  7. Then you can reduce the size of your database.

Good luck to you.

+1


source


if you delete unneeded assemblies, you will be given the option to delete test results associated with the assembly when you delete it. TFS Build Delete options

You may find that test attachments are also taking up a lot of space, you can use the TFS powered test application cleaner to remove them.

TFPT can be found here

0


source


Now I just deleted all assemblies via Visual Studio support, then I disabled TFS, backed up the TFS database and truncated the entire tbl_TestResult table and started TFS again.

TFS hasn't complained and still works well. This solved my problem.

0


source







All Articles