<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package simplepush

import (
	"fmt"
	"net/url"
	"sync"
)

type TestServer struct {
	sync.Mutex
	ClientAddr   string
	EndpointAddr string
	RouterAddr   string
	LogLevel     int32
	Contacts     []string
	app          *Application
	lastErr      error
	isStopping   bool
}

func (t *TestServer) fatal(err error) {
	defer t.Unlock()
	t.Lock()
	if !t.isStopping {
		t.app.Stop()
		t.isStopping = true
	}
	if t.lastErr == nil {
		t.lastErr = err
	}
}

func (t *TestServer) run() {
	err := <-t.app.Run()
	if err != nil {
		t.fatal(err)
	}
}

func (t *TestServer) load() (*Application, error) {
	loaders := PluginLoaders{
		PluginApp: func(app *Application) (HasConfigStruct, error) {
			appConf := app.ConfigStruct().(*ApplicationConfig)
			if err := app.Init(app, appConf); err != nil {
				return nil, fmt.Errorf("Error initializing application: %#v", err)
			}
			return app, nil
		},
		PluginLogger: func(app *Application) (HasConfigStruct, error) {
			logger := NewTextLogger()
			loggerConf := logger.ConfigStruct().(*TextLoggerConfig)
			loggerConf.Filter = int32(t.LogLevel)
			if err := logger.Init(app, loggerConf); err != nil {
				return nil, fmt.Errorf("Error initializing logger: %#v", err)
			}
			return logger, nil<commit_msg>`NewTextLogger()` => `new(StdOutLogger)`.<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package simplepush

import (
	"fmt"
	"net/url"
	"sync"
)

type TestServer struct {
	sync.Mutex
	ClientAddr   string
	EndpointAddr string
	RouterAddr   string
	LogLevel     int32
	Contacts     []string
	app          *Application
	lastErr      error
	isStopping   bool
}

func (t *TestServer) fatal(err error) {
	defer t.Unlock()
	t.Lock()
	if !t.isStopping {
		t.app.Stop()
		t.isStopping = true
	}
	if t.lastErr == nil {
		t.lastErr = err
	}
}

func (t *TestServer) run() {
	err := <-t.app.Run()
	if err != nil {
		t.fatal(err)
	}
}

func (t *TestServer) load() (*Application, error) {
	loaders := PluginLoaders{
		PluginApp: func(app *Application) (HasConfigStruct, error) {
			appConf := app.ConfigStruct().(*ApplicationConfig)
			if err := app.Init(app, appConf); err != nil {
				return nil, fmt.Errorf("Error initializing application: %#v", err)
			}
			return app, nil
		},
		PluginLogger: func(app *Application) (HasConfigStruct, error) {
			logger := new(StdOutLogger)
			loggerConf := logger.ConfigStruct().(*StdOutLoggerConfig)
			loggerConf.Format = "text"
			loggerConf.Filter = int32(t.LogLevel)
			if err := logger.Init(app, loggerConf); err != nil {
				return nil, fmt.Errorf("Error initializing logger: %#v", err)
			}
			return logger, nil
{'fraction_non_alphanumeric': 0.13416274377942167, 'fraction_numerical': 0.005379959650302623, 'mean_word_length': 3.4074074074074074, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6345627', 'n_tokens_mistral': 1104, 'n_tokens_neox': 1017, 'n_words': 296}