The newly restored alliance between the Democratic Party and the AFL-CIO will be severely tested at the grass-roots level next year when 500,000 unionized public workers go to the bargaining table for better wages and benefits.

All the key bargaining battles will occur in labor and Democratic strongholds--New York City and the state, Philadelphia, Baltimore, and Boston--where contracts covering some 262,300 workers represented by the American Federation of State, County and Municipal Employes, a major AFL-CIO affiliate and the nation's largest public employe union, expire next year.

Democratic Party and AFL-CIO leaders lately have been taking practical and rhetorical steps to put aside old grievances and form a stronger union against what they perceive as their common enemy, the Reagan administration.

Party leaders, such as New York Gov. Hugh Carey and Mayor Edward Koch, tried to strengthen that unity in pro-labor speeches earlier this month at the federation's 14th Constitutional Convention in New York.

Koch said his city "prides itself on being a town in which unionism is fostered," and Carey spoke of his "particular pride" that "the beginnings of the labor movement are deeply engraved in the history" of New York State.

But Carey didn't mention his upcoming contract talks with 120,000 state workers, and Koch said nothing about coming negotiations with 110,000 city employes. All, according to their union leaders, will be seeking wage increases and job protection clauses from a city and state reeling from inflation and cutbacks in federal funds and searching for ways to reduce labor costs.

New York City has reduced its public payroll by 8.1 percent, from 238,981 to 221,171 public employes since 1975, trying to cope with rising costs and declining revenues.

And coping hasn't been made any easier by the Reagan administration's taking away about $18.7 billion in federal aid to all state and municipal governments, so far.

As a result, Democratic leaders such as Carey and Koch, who have been currying favor with labor, are now faced with the reality of holding the line at the bargaining table or going to the voters for tax increases. The betting in labor circles is that the politicians would prefer to get tough with the unions.

"It's a hostile environment. We anticipate a difficult time bargaining," said William Lucy, AFSCME secretary-treasurer. "We fully anticipate the employers coming in with the ultimate conservative position--'give up this and give up that.' But we've given up just about all we're about to give."

AFSCME officials argue that public employe wages lag behind those paid in the private sector by an average of $2,500 annually. They say most AFSCME members receive no cost of living allowances.

The union's leaders also say they are concerned about the increasing tendency for state and municipal governments to "contract out" public work--reducing the need to pay health and other benefits normally paid to fulltime public workers